Swatto

Swatto

  • NA
  • 23
  • 11k

Pass object to event handler

Jan 31 2015 6:22 PM
Hi all,

I am trying to pass my object (ThisHost) to the next event handler so I can use it but unsure how, I would appreciate some advice please:

        private void btn_Click (object sender, EventArgs e)
        {
            ContextMenuStrip HostMenu = new ContextMenuStrip();
            

            foreach (Host ThisHost in m_HostList)
            {
                if (((Button)sender).Name == ThisHost.Key.ToString())
                {
                    if (ThisHost.Windows == 1)
                    {
                        HostMenu.Items.Add("RDP");
                        
                    }
                    HostMenu.Click += new EventHandler(HostMenu_Click); // Want to pass 'ThisHost' to to next eventhandler
                }
                
            }
            HostMenu.Show(Cursor.Position);
        }

Answers (2)