Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. How to attach context menu to array of controls?

How to attach context menu to array of controls?

Scheduled Pinned Locked Moved C#
csharpdatabasedata-structurestutorialquestion
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    Kranti1251984
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups