• 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.