19 December, 2014

ContextMenuStrip in winform c#

ContextMenuStrip
1) Drag & Drop 'ContextMenuStrip' on winform [name it as my "subMenuStrip"]
2) Edit items on it.
[ for now i adding items like 'Menu1' & 'Menu2']

Button [drag any winform item : e.g. I use button in it]
1) In 'btnShow' property Select ContextMenuStrip and select  subMenuStrip 
2) You can also set some other properties in it... [i.e. font, backColor]

Run the application and see the result...

Event for "ContextMenuStrip"

On 'subMenuStrip' ItemClick event

private void contextMenuStrip1_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
        {
                //if I select 'Menu1' it will show selected item name in my MessegeBox.
                MessageBox.Show(""+e.ClickedItem+"");
                [ write your code here]
        }

No comments:

Post a Comment