Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I use the Windows look'n'feel for a system tray context menu?

Tags:

c#

.net

winforms

I'm working with a NotifyIcon and ContextMenuStrip, I don't want to use the default menu look and feel which is shipped out of the box with this control which is different to Windows (Vista in my case) by using contextMenu.RenderMode = ToolStripRenderMode.ManagerRenderMode or contextMenu.RenderMode = ToolStripRenderMode.Professional:

alt text

I don't want this using contextMenu.RenderMode = ToolStripRenderMode.System:

alt text

I just want to use the standard, normal Windows "look and feel" as seen in countless, probably non-.net applications *grumble*:

alt textalt text

Any ideas guys on how to achieve this?

like image 892
GONeale Avatar asked Oct 15 '22 16:10

GONeale


1 Answers

On Vista, it renders correctly (i.e., the same way DropBox renders on my machine) when using all the defaults.

Here's a sample program that works for me. Try it, and if it doesn't render correctly for you, try uncommenting the two commented lines.

using System;
using System.Windows.Forms;
using System.Drawing;

public class AC : ApplicationContext
{
    NotifyIcon ni;
    public void menu_Quit(Object sender, EventArgs args)
    {
        ni.Dispose();
        ExitThread();
    }
    public AC()
    {
        ni = new NotifyIcon();
        ni.Icon = SystemIcons.Information;
        ContextMenu menu = new ContextMenu();
        menu.MenuItems.Add("Quit", new EventHandler(menu_Quit));
        ni.ContextMenu = menu;
        ni.Visible = true;
    }
    public static void Main(string[] args)
    {
        //Application.EnableVisualStyles();
        //Application.SetCompatibleTextRenderingDefault(false);
        AC ac = new AC();
        Application.Run(ac);        
    }
}
like image 62
tylerl Avatar answered Oct 20 '22 17:10

tylerl