• 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

    • Which finger's fingernail are we talking about? I can see how not having this info can lead to massive differences in interpretation.
    • This Chinese company is reportedly developing a feature Apple and Samsung can only dream of by Hamid Ganji While companies like Apple and Samsung have been relatively conservative with their devices’ battery capacities in recent years, Chinese manufacturers have taken the competition to the next level by introducing significantly larger batteries. However, the latest report from China suggests that a local company may already be developing a smartphone with a whopping 14,000mAh battery. Chinese leaker Digital Chat Station claimed on Weibo that a smartphone maker is developing a device with a 14,000mAh battery. If true, it would be the largest battery ever used in a smartphone and could, in theory, provide up to a week of battery life on a single charge. The leaker did not reveal the name of the company behind the device, but there are some clues. This week, HONOR unveiled the X80 Pro Max in China with an 11,000mAh battery and 90W wired charging support. The company also launched the Honor Win in January, which packs a 10,000mAh battery. HONOR, a former subsidiary of Huawei, has a proven track record of developing smartphones with unusually large batteries. However, other Chinese brands, including Xiaomi, have also launched devices such as the Xiaomi 17 Pro Max with 7,500mAh batteries. Though Chinese users on Weibo also believe the company behind the new battery is HONOR. Interestingly, Digital Chat Station said the device with the 14,000mAh battery weighs around 220 grams, making it lighter than the Apple iPhone 17 Pro Max (233 grams) and slightly heavier than the Samsung Galaxy S26 Ultra (214 grams). The iPhone 17 Pro Max currently packs a 5,088mAh battery in eSIM-only versions, while the Galaxy S26 Ultra features a 5,000mAh battery. Neither device is expected to see a dramatic increase in battery capacity in its next-generation successor. So when it comes to battery comparison, Chinese brands are unbeaten. HONOR smartphones are currently available in the EU, but the Chinese brand has no official presence in the United States due to restrictions imposed by the U.S. government.
    • Qualcomm takes on NVIDIA with new Dragonfly CPU and AI chips by Pradeep Viswanathan Microsoft, Google, Amazon, AMD, Meta, Apple, OpenAI, and several others have been developing their own chips for AI infrastructure. However, NVIDIA still remains the dominant player in the market. Today, Qualcomm announced a major expansion of its data center infrastructure portfolio to better compete with NVIDIA. The new lineup includes the Qualcomm Dragonfly C1000 CPU, Qualcomm High Bandwidth Compute technology, the Dragonfly AI300 inference accelerator, new connectivity products, and custom silicon solutions. Qualcomm claims that this new lineup improves performance per watt, token throughput, and total cost of ownership for AI data centers. The Dragonfly C1000 is a new data center CPU built with Qualcomm’s custom Oryon cores. This chip will feature more than 250 cores, frequencies above 5GHz, and a chiplet-based design. Qualcomm claims that this new C1000 can deliver more than 2x better performance per watt compared to existing server CPU offerings based on specifications. The Dragonfly C1000 will support PCIe Gen 7 with more than 2TB/s of connectivity, along with CXL, advanced RAS features, and both air and liquid cooling. Qualcomm expects the Dragonfly C1000 to be commercially available in 2028. Additionally, Qualcomm and Meta announced a multi-year, multi-generation agreement under which Qualcomm will supply Dragonfly C1000 data center CPUs for Meta’s next-generation server fleet. Qualcomm also announced High Bandwidth Compute, a new near-memory computing architecture designed to address AI’s memory bandwidth bottleneck. HBC Gen 1 will debut with the Dragonfly AI250, which is expected to sample in mid-2027. The AI250 will deliver 133TB/s per card, an 18x increase in effective memory bandwidth compared to the AI200 with LPDDR5X. The new Dragonfly AI300 with HBC Gen 2 is a rack-level AI inference platform from Qualcomm. Qualcomm claims that the AI300 can deliver 4x to 8x better performance per watt compared to existing GPU-based architectures based on memory bandwidth per watt per card. The Dragonfly AI300 is expected to be available in 2028.
  • Recent Achievements

    • Week One Done
      Meta Plast earned a badge
      Week One Done
    • First Post
      kinowa earned a badge
      First Post
    • Rookie
      krychek57 went up a rank
      Rookie
    • Grand Master
      Jaybonaut went up a rank
      Grand Master
    • One Year In
      Philsl earned a badge
      One Year In
  • Popular Contributors

    1. 1
      +primortal
      461
    2. 2
      +Edouard
      171
    3. 3
      PsYcHoKiLLa
      136
    4. 4
      Michael Scrip
      78
    5. 5
      Xenon
      77
  • Tell a friend

    Love Neowin? Tell a friend!