Getting the parent object from a context menu

S

scott

Hi all, im not sure if this is possible but would be a grate help if it was.



I have a several buttons and all have a context menu. That context menu has
one menu item called delete. All context menus share the same click event.



I want to be able to determine which button it has come from (get the
system.windows.form.button) when the delete menu is clicked.



Is this at all possible ?



Thanks for any responses



Scott.
 
C

Chris Jobson

Use the ContextMenu's SourceControl property, e.g.

private void menuItem1_Click(object sender, System.EventArgs e) {
MenuItem mi = (MenuItem)sender;
ContextMenu cm = (ContextMenu)mi.Parent;
Control c = cm.SourceControl;
MessageBox.Show(c.Text);
}

Chris Jobson
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top