views:

276

answers:

3

What is the best method of using native menus in C#?

Edit: I want to use the native menu because it's better looking than the ugly .NET menu. Can someone explain to me exactly how I can use it?

A: 

If you are referring to the System Menu (the context menu that pops up when right-clicking on a window's title bar), here is a great article on CodeGuru for manipulating it in C#.

David Brown
+3  A: 

In the System.Windows.Forms namespace, you'll find the classes: Menu, ContextMenu, MenuItem, MenuStrip, ContextMenuStrip, ToolBar, ToolStrip, and others.

These classes are simply wrappers around the Win32 API calls that implement these controls natively. The same is true for nearly every class in the System.Windows.Forms namespace; when you use these classes, you're actually using the native controls.

So the best method of using native menus in .NET is to use the controls .NET provides for to display menus, as mentioned above. Whichever ones you use depends on what you're trying to accomplish. The simplest option for attaching a main menu to a form is using the Menu object, populated with a MenuItem set.

tylerl
A: 

You can't get it w/o a bunch of API hacking. Besides, you can get a better menu easier.

Joshua
Exactly what does this answer actually mean...?
Adam Robinson
"API Hacking"? Essentially this answer reads "there's a better way, but I won't tell you what it is, nor do I really know what it is that what I'm not-proposing is superior to."
pyrochild
The better way was already listed by tylerl.
Joshua