Thursday, April 28, 2011

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

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 text alt text

Any ideas guys on how to achieve this?

From stackoverflow
  • 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);  
     }
    }
    
    GONeale : Thanks tyler, I found out what I was doing wrong with help from your example. I was using a ContextMenuStrip when I should have been using a ContextMenu. Thanks. Although not sure how they have made bold entry items now. Shrug. Probably overriden somehow.
    tylerl : menuItem.FontWeight
    GONeale : Nah. menuItem.DefaultItem it was.

0 comments:

Post a Comment