Spread Windows Forms 7.0 Product Documentation
Adding a Context Menu to a Component
Support Options
Spread Windows Forms 7.0 Product Documentation > Developer's Guide > Customizing Sheet Interaction > Customizing Interaction with the Overall Component > Adding a Context Menu to a Component

Glossary Item Box

You can create a context menu and add it to the ContextMenu property of the FpSpread component (which is inherited from the System.Windows.Forms.Control). The component automatically displays this menu of context-specific menu options when you right click on the component. A context menu is also known as a shortcut menu. For more information, refer to the Microsoft .NET documentation about context menu (or shortcut menu). The figure shows a context menu with two choices. The code for this is shown in the example.

Context Menu Example

The scroll bars have, by default, a context menu of their own.

Add a context menu using the ContextMenu property and define the menu items. This example shows the code. At design time, you could also drop in a Context Menu from the Toolbox and look at the code generated by that to learn more.

Example

C# Copy Code
ContextMenu custommenu = new ContextMenu();
custommenu.MenuItems.Add("&Table");
custommenu.MenuItems.Add("&Color", new EventHandler(ContextMenu_Color);
fpSpread1.ContextMenu = custommenu;

private void ContextMenu_Color(object sender, System.EventArgs e)
{
    MessageBox.Show("You chose color.");
}
VB Copy Code
Dim custommenu As New ContextMenu
custommenu.MenuItems.Add("&Table")
custommenu.MenuItems.Add("&Color", New EventHandler(AddressOf ContextMenu_Color))
FpSpread1.ContextMenu = custommenu

Private Sub ContextMenu_Color(ByVal sender As Object, ByVal e As System.EventArgs)
     MsgBox("You chose color.")
End Sub
© 2002-2014 ComponentOne, a division of GrapeCity. All Rights Reserved.