ICreate.Controls.Bars Send comments on this topic.
Menu Property
See Also  Example
ICreate.Controls.Bars Namespace > CommandItem Class : Menu Property






Gets or sets the ContextMenuStrip associated with the CommandItem.

Syntax

Visual Basic (Declaration) 
Public Property Menu As ContextMenuStrip
Visual Basic (Usage)Copy Code
Dim instance As CommandItem
Dim value As ContextMenuStrip
 
instance.Menu = value
 
value = instance.Menu
C# 
public ContextMenuStrip Menu {get; set;}
Delphi 
public read-write property Menu: ContextMenuStrip; 
JScript 
public function get,set Menu : ContextMenuStrip
Managed Extensions for C++ 
public: __property ContextMenuStrip get_Menu();
public: __property void set_Menu( 
   ContextMenuStrip value
);
C++/CLI 
public:
property ContextMenuStrip Menu {
   ContextMenuStrip get();
   void set (ContextMenuStrip value);
}

Return Value

A reference to a ContextMenuStrip, this property specifies the menu displayed when the CommandItem is clicked. The default value is null (Nothing for Visual Basic).

Example

The example below shown how to create a ContextMenuStrip, assign this ContextMenuStrip to a CommandButton and specify that the menu should be displayed at the bottom of the CommandButton. To execute this example create a WinForm application, add a CommandButton to the Form, implement the Form as shown below, compile and run the application.
C#Copy Code
using System; 
using System.Windows.Forms; 
 
using ICreate.Controls.Bars; 
 
namespace ExamplesCSharp 

    public partial class MenuPropertyExample : Form 
    { 
        public MenuPropertyExample() 
        { 
            InitializeComponent(); 
 
            ContextMenuStrip contextMenu = CreateContextMenu(); 
            commandButton.Menu = contextMenu; 
            commandButton.MenuPosition = Position.Bottom; 
        } 
 
        private ContextMenuStrip CreateContextMenu() 
        { 
            ContextMenuStrip contextMenu = new ContextMenuStrip(); 
 
            ToolStripMenuItem item1 = new ToolStripMenuItem("Menu item 1"); 
            item1.Click += new EventHandler(OnMenuItem1Clicked); 
            contextMenu.Items.Add(item1); 
 
            ToolStripMenuItem item2 = new ToolStripMenuItem("Menu item 2"); 
            item2.Click += new EventHandler(OnMenuItem2Clicked); 
            contextMenu.Items.Add(item2); 
 
            ToolStripMenuItem item3 = new ToolStripMenuItem("Menu item 3"); 
            item3.Click += new EventHandler(OnMenuItem3Clicked); 
            contextMenu.Items.Add(item3); 
 
            return contextMenu; 
        } 
 
        void OnMenuItem1Clicked(object sender, EventArgs e) 
        { 
            MessageBox.Show("Menu item 1 clicked"); 
        } 
 
        void OnMenuItem2Clicked(object sender, EventArgs e) 
        { 
            MessageBox.Show("Menu item 2 clicked"); 
        } 
 
        void OnMenuItem3Clicked(object sender, EventArgs e) 
        { 
            MessageBox.Show("Menu item 3 clicked"); 
        } 
    } 
}
Visual BasicCopy Code
Imports ICreate.Controls.Bars

Public Class MenuPropertyExample

    Public Sub New()

        InitializeComponent()

        Dim contextMenu As ContextMenuStrip = CreateContextMenu()
        CommandButton.Menu = contextMenu
        CommandButton.MenuPosition = Position.Bottom

    End Sub

    Private Function CreateContextMenu() As ContextMenuStrip
        Dim contextMenu As New ContextMenuStrip()

        Dim item1 As New ToolStripMenuItem("Menu item 1")
        AddHandler item1.Click, AddressOf OnMenuItem1Clicked
        contextMenu.Items.Add(item1)

        Dim item2 As New ToolStripMenuItem("Menu item 2")
        AddHandler item2.Click, AddressOf OnMenuItem2Clicked
        contextMenu.Items.Add(item2)

        Dim item3 As New ToolStripMenuItem("Menu item 3")
        AddHandler item3.Click, AddressOf OnMenuItem3Clicked
        contextMenu.Items.Add(item3)

        Return contextMenu
    End Function


    Sub OnMenuItem1Clicked(ByVal sender As Object, ByVal e As EventArgs)
        MessageBox.Show("Menu item 1 clicked")
    End Sub


    Sub OnMenuItem2Clicked(ByVal sender As Object, ByVal e As EventArgs)
        MessageBox.Show("Menu item 2 clicked")
    End Sub


    Sub OnMenuItem3Clicked(ByVal sender As Object, ByVal e As EventArgs)
        MessageBox.Show("Menu item 3 clicked")
    End Sub

End Class

Remarks

If a CommandItem is linked to a ContextMenuStrip via its Menu property and this ContextMenuStrip has at least one item, then the ContextMenuStrip is displayed when the CommandItem is clicked. The position at which the menu is shown is specified using the MenuPosition property. For a CommandButton with SubButtonPosition any value other than None, the ContextMenuStrip is displayed when the sub button and not the main button is clicked.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

See Also