• 0

[C#] Context Menu Strip with Windows Vista look and feel


Question

Hi,

I've searched and searched google but can't find anything... I'm currently using 2 context menu strips in my application, one for the notification icon and another for the contextual menu of a textbox. I want them to have the look and feel of menus in Vista with the possibility to use icons. However, if the application is used on XP, I want the menus to have the look and feel of XP, also using the icons.

Can anyone help me out?

Recommended Posts

  • 0
Ummm... it'll help you because you can query the system (through Windows.Forms) to get the bitmaps/colours making up the interface at any particular moment, and then draw the menu dynamically using GDI+. There are a whole set of classes in .NET for exactly this type of scenario.

There's no need for attitude here. Since you've spent two weeks on this, I was JUST wondering why you hadn't already considered the path of least resistance..........

Hey dannysmurf,

Are you referring to the VisualStyles namespace? For some weird reason a lot of the visual style static classes, which represents bitmap state representations of common controls do not work under vista, for example, the Menu class isn't supported and as a result you can't query the OS for it, unless you go through other means of finding where the actualy menu items come from?

Winston

  • 0
Hey dannysmurf,

Are you referring to the VisualStyles namespace? For some weird reason a lot of the visual style static classes, which represents bitmap state representations of common controls do not work under vista, for example, the Menu class isn't supported and as a result you can't query the OS for it, unless you go through other means of finding where the actualy menu items come from?

Winston

Off the top of my head, I don't recall which namespace/classes I am referring to, but VisualStyles sounds right. It has been a while since I used them (and then, only on XP), so you may be quite right about the whole shebang not working under Vista; I honestly don't know.

  • 0

you need to override the paint event of the menu & use the menu background color

// fill selection rectangle

e.Graphics.FillRectangle(new SolidBrush(Globals.SelectionColor), e.Bounds);

// Draw borders

e.Graphics.DrawRectangle(new Pen(Globals.MenuDarkColor), e.Bounds.X, e.Bounds.Y, e.Bounds.Width - 1, e.Bounds.Height - 1);

Fill color should be "Gainsboro" or something related to exact vista color..

And on move hover you need to draw a rectange horizontal gradient starting from transparent to light blue or something related to that..

I will do the code & paste the code it either tommorrow or this weekend...because i will be travelling on other days for official meetings :-(

  • 0

I don't mean to resurrect such an old topic, but I bookmarked this page a while back so I could post when I had finished my Vista Menu component:

post-44539-1210957303.png

It's open source, written in C# and works with every .NET 2.0+ language. I've written a short article (Vista Menu with Icons in C#) introducing it which includes the download link.

I hope you find it useful.

  • 0

This is cool, thanks for all your effort on this.

However, a couple of questions because I don't have the time to test this out and I will not use it for now cause the project where I'll use is halted for the time being...

1) Will it work for any kind of menu? I mean, top menu for a form, context menu of controls that support it (like a texbox) and most important (for me), context menu of a notification icon?

2) What if some user is using a patched uxtheme.dll or WindowBlinds (either on Vista or XP or even 98), how this control handles the menu drawing?

  • 0
This is cool, thanks for all your effort on this.

However, a couple of questions because I don't have the time to test this out and I will not use it for now cause the project where I'll use is halted for the time being...

1) Will it work for any kind of menu? I mean, top menu for a form, context menu of controls that support it (like a texbox) and most important (for me), context menu of a notification icon?

It works with every control that displays MenuItems. That is, it works with the "MainMenu" control and the "ContextMenu" control. (But not the ContextMenuStrip nor MenuStrip).

One VistaMenu control per form handles all the MenuItems.

2) What if some user is using a patched uxtheme.dll or WindowBlinds (either on Vista or XP or even 98), how this control handles the menu drawing?

I separated the drawing into two groups:

1. Vista+ (i.e. Vista, 2008, any new version)

2. Pre-Vista

For Vista+ I used the correct Windows way to add icons to menus. I don't do any "owner-drawing". I just use the same method Microsoft uses to add icons. (Look in the source code for the particulars.)

For Pre-Vista I owner-draw the menus because there's no good way draw icons with Windows API. Also, menus weren't themed with 'uxtheme.dll' (or the patched version) in Windows XP, they just use solid colors. My code uses whatever system colors and system fonts are defined for the menu items.

As far WindowBlinds, I have no idea.

  • 0

We need some testing to be done then... :p

Cause this control is useless (at least for me, no offense though, great job on the control ;)) if it doesn't work everywhere. By 'everywhere' I mean WindowBlinds and such... The idea is our application to have the menus look and feel exactly the way every other menu in the system, be it on XP/Vista and/or using something like WindowBlinds or not...

Understand what I mean?

And I'm not sure about that uxtheme.dll and solid colors thing. That might be true for the default Luna visual style but there are numerous visual styles out there that have graphical menus instead of solid colors and they don't need any program to work, just a patched uxtheme.dll.

  • 0
We need some testing to be done then... :p

Cause this control is useless (at least for me, no offense though, great job on the control ;)) if it doesn't work everywhere. By 'everywhere' I mean WindowBlinds and such... The idea is our application to have the menus look and feel exactly the way every other menu in the system, be it on XP/Vista and/or using something like WindowBlinds or not...

Understand what I mean?

I do understand. Nothing works everywhere. The source is available, as are the compiled binaries. You could run the compiled binaries without touching the source and confirm whether or not WindowsBlinds works.

If it does, great! If it doesn't, add few lines of code to what I've already written and send me the changes. Or not, there's no obligation.

And I'm not sure about that uxtheme.dll and solid colors thing. That might be true for the default Luna visual style but there are numerous visual styles out there that have graphical menus instead of solid colors and they don't need any program to work, just a patched uxtheme.dll.

The uxtheme API doesn't store menu theme data for Pre-Vista versions of Windows. Everything is just solid colors (which I render correctly based on the user's color settings). See this and this.

If WindowsBlinds overrides the default Windows drawing, then I'll be glad to accept any patches to my implementation to handle WindowsBlinds. However, I won't dig through the WindowsBlinds API looking for a solution.

  • 0
If it does, great! If it doesn't, add few lines of code to what I've already written and send me the changes. Or not, there's no obligation.

If I could code something like that, I wouldn't have created this topic in the first place...

The uxtheme API doesn't store menu theme data for Pre-Vista versions of Windows. Everything is just solid colors (which I render correctly based on the user's color settings). See this and this.

That can be true but I could almost swear that I've really seen themes (specifically for uxtheme.dll patched versions) that had menus with gradients and such...

If WindowsBlinds overrides the default Windows drawing, then I'll be glad to accept any patches to my implementation to handle WindowsBlinds. However, I won't dig through the WindowsBlinds API looking for a solution.

What's the point on even releasing this control if you don't care about suggestions to improve it? We are not talking about a feature in a application where some might find useful and others don't and/or that this feature is something that makes no sense for your application (in your point of view as you made this, initially, for you; I suppose...). This is a control to have Vista menus look and feel like they belong on Vista but it's a must to have compatibility with everything related to menus. There are tons of people using WindowBlinds and someone that uses your control will want to make sure their application reaches as much users as possible.

Yeah yeah, I know the source code is available and bla bla, but that's not a reason to not improve your own product if you decided to create it and share with the public in the first place.

I'm not saying you should do it and that you are obligated to it, because your not and I really appreciate your work so far, but you could at least try and spend a few minutes to see if it works or not and if it's easy to come up with a solution or not. Instead, your are just saying you are not going to do it without even trying...

No hard feelings... :)

  • 0
I'm not saying you should do it and that you are obligated to it, because your not and I really appreciate your work so far, but you could at least try and spend a few minutes to see if it works or not and if it's easy to come up with a solution or not. Instead, your are just saying you are not going to do it without even trying...

This argument is beginning to get absurd. We're fighting about a potential bug that may or may not exist.

Before any action can be taken, you must show me a screenshot where my VistaMenu control fails. Also tell me how to reproduce the problem. If the bug is a case of me not handling all of Windows theme API correctly, then I'll fix the bug.

If it's a case of WindowsBlinds doing its own propreitary modification of Windows API (by intercepting hooks and handles and however else they do it) then I'll consider fixing the problem.

  • 0

Well, just to let you know that I tested the control on virtual XP (with VMware) and tried both uxtheme.dll and WindowBlinds and it worked flawless (as far as I could tell) for both.

Congrats on the great control.

Now you just need to make it more popular and create a better homepage for it? Have you though about posting it on CodePlex?

Just a suggestion ;)

  • 0
Now you just need to make it more popular and create a better homepage for it? Have you though about posting it on CodePlex?

If it's any consolation, I'll be redesigning my site later this summer. It'll have a nice home for all my open source controls (VistaMenu, SplitButton, etc.) instead of being spread across blog posts. But no, it won't be appearing on CodePlex.

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

    • It sounds like you’re trying to rewrite a narrative to align this layoff with your political beliefs. Games can be horrible, whatever backwards notions you have don’t change that bungie has problems, mostly with just bad games, and arrogance. When they pushed Microsoft to let them be independent they lost their way. They hired on a bunch of people and they couldn’t justify the employee count consistent with their revenue.
    • Trying out Noctalia v5 on CachyOS  
    • Calibre 9.10 by Razvan Serea  Calibre is an open source e-book library management application that enables you to manage your e-book collection, convert e-books between different formats, synchronize with popular e-book reader devices, and read your e-books with the included viewer. It acts as an e-library and also allows for format conversion, news feeds to e-book conversion, as well as e-book reader sync features and an integrated e-book viewer. Calibre's features include: library management; format conversion (all major ebook formats); syncing to e-book reader devices; fetching news from the Web and converting it into ebook form; viewing many different e-book formats, giving you access to your book collection over the internet using just a browser. Calibre 9.10 changelog: New features Content server: A new "modern" interface with a sidebar to ease navigation Content server: When used with HTTPS allow installation as a PWA (Progressive Web App) Edit book: Saved searches: When filtering the list of saved searches match by keywords CSS parsing: Add support for CSS Level 4 selectors Cover grid: When using an image larger than the viewport as a texture scale it to fit the viewport Annotations browser: Allow restricting displayed annotations by custom annotation styles as well Edit book: Compress images: Add option to convert PNG images to JPEG or WEBP Bug fixes E-book viewer: Fix IME on Windows not working when typing in notes for highlights Conversion: Heuristics: Improve performance in some pathological cases SNB Input: Fix error on some input files Windows: fix rare crash when too many notifications are displayed at once Fix duplicating of books not duplicating value from enumerated columns when the column has a default value defined Fix a regression in 9.8 that caused errors from AI plugin providers to be silently swallowed and not displayed to user Fix CSV export invalid when exporting comments field Disallow Python templates when reading book metadata (CVE-2026-53511) Improved news sources The Week Economist Espresso Horizons Download: Calibre 9.10 | Portable | ~200.0 MB (Open Source) Download: Calibre for MacOS | 327.0 MB Download: Calibre for Linux View: Calibre Home Page | Calibre Screenshot Get alerted to all of our Software updates on Twitter at @NeowinSoftware
    • Malwarebytes Anti-Malware 5.6.1.257 by Razvan Serea Malwarebytes is a high performance anti-malware application that thoroughly removes even the most advanced malware and spyware. Malwarebytes version 5.**** brings comprehensive protection against today’s threat landscape so that you can finally replace your traditional antivirus. You can finally replace your traditional antivirus, thanks to a innovative and layered approach to prevent malware infections using a healthy combination of proactive and signature-less technologies. While signatures are still effective against threats like potentially unwanted programs, the majority of malware detection events already come from signature-less technologies like Malwarebytes Anti-Exploit and Malwarebytes Anti-Ransomware; that trend will only continue to grow. For many of you, this is something you already know, since over 50% of the users already run Malwarebytes as their sole security software, without any third-party antivirus. What's new in Malwarebytes 5.****: Unified user experience - For the first time, Malwarebytes now provides a consistent experience across all of our desktop and mobile products courtesy of an all new and reimagined user experience powered by a faster and more responsive UI all managed through an intuitive dashboard. Modern security and privacy integrations - Antivirus and ultra-fast VPN come together seamlessly in one easy-to-use solution. Whether you’re looking for a next-gen VPN to secure your online activity, or harnessing the power of Browser Guard to block ad trackers and scam sites, taking charge of your privacy is simple. Trusted Advisor - Empowers you with real-time insights, easy-to-read protection score and expert guidance that puts you in control over your security and privacy. Malwarebytes 5.6.1.257 changelog: Features and improvements Updated the sign-in section of the My Subscription page to clarify that users can activate their subscription by signing in with their Malwarebytes account. Updated the uninstall flow to collect more meaningful insights and address customer concerns. Refreshed the app's tutorial layout for a better look and feel. Issues fixed Fixed an outdated link when clicking Take action after running a Digital Footprint Scan. Miscellaneous bug fixes. Download: Malwarebytes 5.6.1.257 | 472.0 MB (Free, paid upgrade available) Links: Malwarebytes Website | Screenshot Get alerted to all of our Software updates on Twitter at @NeowinSoftware
  • Recent Achievements

    • Week One Done
      xvvxcvv earned a badge
      Week One Done
    • One Month Later
      xvvxcvv earned a badge
      One Month Later
    • Enthusiast
      Xonos went up a rank
      Enthusiast
    • Conversation Starter
      Admir earned a badge
      Conversation Starter
    • First Post
      The_Focal_Point earned a badge
      First Post
  • Popular Contributors

    1. 1
      +primortal
      405
    2. 2
      +Edouard
      168
    3. 3
      PsYcHoKiLLa
      129
    4. 4
      neufuse
      69
    5. 5
      Xenon
      68
  • Tell a friend

    Love Neowin? Tell a friend!