Can I create a context menu with multiple columns in .NET Windows Forms?

I want to create a context menu with multiple columns. Basically it will look like this:

First item  | [common option] | All Options >
Second item | [common option] | All Options >
Third item  | [common option] | All Options >
Fourth item | [common option] | All Options >

Thus, basically there is a bunch of elements (generated at runtime), each element can start on its own; or with a widely used option; or you can get a submenu with all possible parameters.

How can i do this? I am trying to use both ContextMenuStrip, and ContextMenu, but they seem to have no such parameters. However, I seem to remember that somewhere I saw a menu with several columns ...

I would prefer a Windows Forms solution because I have no WPF experience. Oh, and this context menu will open when you click on the icon in the notification area (aka systray).

+5
source share
2 answers

I don’t know about ContextMenuStrip, which is a menu completely created in .NET code, but you can do it with ContextMenu, which is a wrapper in your own system menus.

The key sets flags MFT_MENUBREAKeither MFT_MENUBARBREAKfor individual menu items (s) that are displayed as properties in MenuItemclass : MenuItem.Breakand MenuItem.BarBreak, respectively.

The former only places the menu item in a new column, and the latter places the item in a new column and separates the column with an engraved vertical line.

From the MSDN example:

public void CreateMyMenus()
{
    // Create three top-level menu items.
    MenuItem menuItem1 = new MenuItem("&File");
    MenuItem menuItem2 = new MenuItem("&New");
    MenuItem menuItem3 = new MenuItem("&Open");

    // Set the BarBreak property to display horizontally.
    menuItem2.BarBreak = true;
    menuItem3.BarBreak = true;

    // Add menuItem2 and menuItem3 to the menuItem1 list of menu items.
    menuItem1.MenuItems.Add(menuItem2);
    menuItem1.MenuItems.Add(menuItem3);
}
+5
source

WinForms : . , .

, ( WPF , WPF , ).

0

All Articles