How to attach context menu to array of controls?
-
Hi, I'm writing an application in c#.net, in which i've created array of control Button. I want to display a menu when user clicks any of the buttons in the array. I was able to create context menu for a single button, but not for the array, as coded below ...
public class ButtonArray : System.Collections.CollectionBase { private readonly System.Windows.Forms.Form ContainerControl; public ButtonArray(System.Windows.Forms.Form Cont) { ContainerControl = Cont; } public void AddButton() { //code to create button btButton.MouseDown += new MouseEventHandler(btButton_MouseDown); } public void btButton_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e) { contextMenuStudInfo = new System.Windows.Forms.ContextMenu(); System.Windows.Forms.MenuItem menuItem1; menuItem1 = new System.Windows.Forms.MenuItem(); System.Windows.Forms.MenuItem menuItem2; menuItem2 = new System.Windows.Forms.MenuItem(); contextMenuStudInfo.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] { menuItem1, menuItem2 }); menuItem1.Index = 0; menuItem1.Text = "Mark Present"; menuItem2.Index = 1; menuItem2.Text = "Mark Absent"; this.btButton.ContextMenu = contextMenuStudInfo; } }
how to attach the context menu to each member of button control array? Thanks, Kranti -- modified at 5:31 Wednesday 3rd May, 2006