Shows a user-specified context menu beneath this button.
ShowMenu automatically displays a specified context menu in the appropriate position below or above the button. However, unlike the Show method of ContextMenu, the menu shown by ShowMenu will never overlap the button. You can also display the default context menu for a button with the PerformMenuClick method.
This example handles the MenuClick event and generates custom menus for the buttons called btnBack and btnForward. When the user clicks on one of the menu items, their selection is displayed in a message box.
The requirements for this example are:
private void bandWeb_MenuClick(object sender, Skybound.Rebar.RebarButtonEventArgs e) { // show custom menus for the buttons named 'btnBack' and 'btnForward' if (e.Button.Name == "btnBack" || e.Button.Name == "btnForward") { using (ContextMenu menu = new ContextMenu()) { // create a new menu with 3 items for the 'back' button if (e.Button.Name == "Back") menu.MenuItems.AddRange(new MenuItem[] { new MenuItem("Back one step"), new MenuItem("Back two steps"), new MenuItem("Back three steps") }); // create a new menu with 2 items for the 'forward' button else if (e.Button.Name == "Forward") menu.MenuItems.AddRange(new MenuItem[] { new MenuItem("Forward one step"), new MenuItem("Forward two steps") }); foreach (MenuItem item in menu.MenuItems) item.Click += new EventHandler(OnWebNavigationClick); // call ShowMenu e.Button.ShowMenu(menu); } // let the band know we handled the event. e.Handled = true; } } private void OnWebNavigationClick(object sender, System.EventArgs e) { MessageBox.Show("You clicked '" + (sender as MenuItem).Text + "'."); }
RebarButton Class | Skybound.Rebar Namespace