C#
protected void AddMenu()
{
// Create the MenuControl instance
MenuControl topMenu = new MenuControl();
// Create and add a single top level menu item
MenuCommand top = new MenuCommand("TestTop");
// Associate appropriate status bar description for item
top.Description = "Description of the submenu";
topMenu.MenuCommands.Add(top);
// Create and add a submenu with two items
MenuCommand sub1 = new MenuCommand("TestSub1");
MenuCommand sub2 = new MenuCommand("TestSub2");
// Associate appropriate status bar descriptions for each menu
sub1.Description = "Description for TestSub1";
sub2.Description = "Description for TestSub2";
top.MenuCommands.AddRange(new MenuCommand[]{sub1, sub2});
// Hook into selection events
_topMenu.Selected += new CommandHandler(OnSelected);
_topMenu.Deselected += new CommandHandler(OnDeselected);
// Add to the Form
Controls.Add(_topMenu);
}
protected void OnSelected(MenuCommand mc)
{
_statusBarPanel.SetStatusBarText(mc.Description);
}
protected void OnDeselected(MenuCommand mc)
{
_statusBarPanel.SetStatusBarText("");
}
VB.NET
Protected Sub AddMenu()
' Create the MenuControl instance
Dim topMenu As New MenuControl()
' Create and add a single top level menu item
Dim top As New MenuCommand("TestTop")
' Associate appropriate status bar description for item
top.Description = "Description of the submenu"
topMenu.MenuCommands.Add(top)
' Create and add a submenu with two items
Dim sub1 As New MenuCommand("TestSub1")
Dim sub2 As New MenuCommand("TestSub2")
' Associate appropriate status bar descriptions for each menu
sub1.Description = "Description for TestSub1"
sub2.Description = "Description for TestSub2"
top.MenuCommands.AddRange(new MenuCommand(){sub1, sub2})
' Hook into selection events
AddHandler _topMenu.Selected, AddressOf OnSelected
AddHandler _topMenu.Deselected, AddressOf OnDeselected
' Add to the Form
Controls.Add(_topMenu)
End Sub
Protected Sub OnSelected(ByVal mc As MenuCommand)
_statusBarPanel.SetStatusBarText(mc.Description)
End Sub
Protected Sub OnDeselected(ByVal mc As MenuCommand)
_statusBarPanel.SetStatusBarText("")
End Sub
|