Joke Collection Website - Joke collection - C# winform dynamically generates menus with contextmenustrip
C# winform dynamically generates menus with contextmenustrip
Protected coverage void OnLoad(EventArgs e)
{
Base. Load (e);
//Add menu 1
ToolStripMenuItem subitem;
SubItem = AddContextMenu ("news ",context menustrip 1.items,null);
//Add a submenu
AddContextMenu ("Today's news", sub-item. Drop-down item, new event handler (menu clicked));
AddContextMenu ("today's concern", sub-item. DropdownItems, New Eventhandler);
//Add Menu 2
SubItem = AddContextMenu ("joke ",context menustrip 1.items,null);
//Add a submenu
AddContextMenu ("modern joke", subtitle. Drop-down item, new event handler (menu clicked));
AddContextMenu ("ancient joke", sub-item. Drop-down item, new event handler (menu clicked));
}
///& lt; Summary & gt
///Add a submenu
///& lt; /summary & gt;
///& lt; Param name = "text"> The text to be displayed. If it is-,it will be displayed as a separator.
///& lt; Param name = "cms"> submenu set to add to.
///& lt; Param name = "callback"> Event triggered when clicked.
///& lt; The submenu generated by returns & gt returned null.
Toolstrip menuitem add context menu (string text, ToolStripItemCollection cms, EventHandler callback)
{
if (text == "-")
{
toolstrip separator tsp = new toolstrip separator();
cms。 Add (tsp);
Returns null
}
else if(! String. IsNullOrEmpty(text))
{
toolstrip menuitem tsmi = new toolstrip menuitem(text);
If (callback! = null) tsmi。 Click+= Call Back;
cms。 add(tsmi);
Return to tsmi
}
Returns null
}
Void MenuClicked (object sender, event parameter e)
{
MessageBox。 Show ("You clicked the menu item ["+((sender as ToolStripMenuItem)). text)+"]";
}
- Previous article:Information about rabbits
- Next article:What are the disadvantages of intensive phobia?
- Related articles
- What are the abbreviations used by many people in World of Warcraft?
- Ask a joke about the toilet! ~
- A cold joke about the college entrance examination
- Who knows where the jokes about dog biting and Lv Dongbin are?
- Super joke of group owner
- What are the top ten horrible creatures in the universe?
- Snail boy
- In a bad mood! ! Everybody tell me some jokes.
- Reading and Writing of Secondary Animals Picking Fruits in Orchards
- Lin Daiyu is so gentle, why do many people say she is "snarky"?