2
Answers

Pass object to event handler

Swatto

Swatto

9y
747
1
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)