• 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

    • Speak for yourself. I saw it on Feedly, came here to read it, and did read it until the steps to activate. I skipped them to read the last paragraph. I knew it was probably not "the most requested feature", but knowing Neowin, I knew the article was going to talk about a feature nonetheless. I've seen Neowin in its best and worst.
    • See if this article I wrote the other day works for you.
    • We could disable web results as far back as Windows 10 everywhere.
    • No, it wasn't "huge", it is lame, and it was lame back then.
    • 7 Days: SPECS for $2,195, Firefox Nova 2026, first AI arts museum, and iPhone price hike by Aditya Tiwari 7 Days is a weekly roundup of picks of what's been happening in the world of technology - written with a dash of humor, a hint of exasperation, and an endless supply of (black) coffee. This week's highlights include Linux 7.1 stable release, Samsung pulling the plug on its VPN, and Microsoft Edge bringing the sign-in with Google experience. Let's get started. You can check out the recent issues of the 7 Days weekly roundup. Mozilla highlights Firefox Nova Mozilla showed off a new Firefox roadmap highlighting the browser's upcoming features and the Nova 2026 redesign. Interested users and enthusiasts can check out what's cooking and share feedback on the upcoming additions. Besides this, Firefox 152 brought Tab Groups to Android as one of its biggest additions, along with a redesigned Settings experience. World's first AI arts museum Image: Google Google opened the world's first AI arts museum in Los Angeles on June 20, which it named Dataland. The museum, spanning 25,000 square feet, was built in collaboration with media artist Refik Anadol, who has worked with Google since 2016. It will have real-time visuals and react dynamically to visitors. Salesforce shopping bag In the latest acquisition news, Salesforce is buying the customer support software company Fin (formerly Intercom) for $3.6 billion to strengthen its AI customer service ambitions and Agentforce platform. The transaction is expected to close in the fourth quarter of its fiscal year 2027. UK follows Australia Prime Minister Keir Starmer announced that the country will ban social media for kids under 16, which is happening after a six-week trial involving 300 teenagers, stating that social media is making them unhappy and easier for bullies to harass and abuse them. Starmer continued that social media is addictive and uses an infinite scroll designed to lock users in for hours. The UK government plans to take action on gaming services and livestreaming platforms. Meanwhile, its age verification rules have also become a hot topic and a point of criticism. Our Features Our coffee-powered team publishes a platter of editorials, opinion posts, and guides. Check them out: Microsoft hides these secret Windows 11 performance boost settings available on every PC Microsoft Paint used to be my favorite Windows app as a kid, and it's still pretty good Why you need to take back control of your synced passwords and how to go about doing that The Microsoft Office feature that time forgot This week in software news Catch up on some of the latest software news updates that arrived throughout the week: Another Samsung shutdown: The South Korean giant is pulling the plug on the Samsung Max VPN app, which is used by more than 50 million users. The app has stopped working since June 15, and Samsung didn't provide a reason for the unexpected move. Photoshop power-up: The popular image editing app is getting a big 20% performance boost on x86-64 (AMD64) systems and a 13% bump-up on Arm devices. Here, the credit goes to a new performance boost added to Windows 11 following a combined effort between Microsoft and Adobe. Linux 7.1 arrives: Linus Torvalds released the stable Linux 7.1 kernel this week, which brings critical driver updates and a rewritten storage driver. You should look out for the new NTFS driver, Intel FRED for improved performance on Panther Lake and future CPUs. Ads in your games: Electronic Arts is launching a new advertising platform to serve in-game ads and enable brands to feature their products in titles like EA Sports FC, Madden, NHL, Skate, or The Sims. With EA Advertising, brands will be able to inject their products into games in real-time via dynamic placement, in places like stadium signage in sports games. Sign in with Google: Microsoft Edge browser is finally getting direct Google account sign-in support from the profile menu and the Edge sign-in screen, allowing users to sync browser data without an MSA. Rufus 4.15 beta: The latest Rufus update is out with important fixes for "silent" Windows 11 installation, patches for ARM-based PCs, and more. Rufus 4.15 beta is now available to download from its official GitHub repository. NVIDIA 610.62: GeForce hardware owners can get their hands on the new WHQL-certified 610.62 Game Ready driver, which carries a lot of bug fixes and support for the fast-paced 6v6 movement shooter Empulse. Zed 1.7.2: The latest update adds "/compact" AI chat summarization, new models, settings kill management, git graph commands, and UI improvements. This week in hardware news Image: Snap Inc. Catch up on some of the latest software news updates that arrived throughout the week: SPECS for $2,195: Snap Inc. launched its new AR-powered wearable computer. SPECS are now available for pre-order and will start shipping in the US, UK, and France later this year. No CMF phone in 2026: The global memory shortage has also knocked Nothing's door and it has decided to hold the launch of CMF Phone 2 Pro's successor this year. That said, Nothing still has planned several new products under the CMF brand. 12th Gen Surface Pro: It's been two years since the original pair of Copilot+ PCs arrived. Now, Microsoft upgraded the lineup with Snapdragon X2-based devices for the 12th-gen Surface Pro, which promises up to 53% faster graphics. New Surface Laptop: The refreshed Surface Laptop is also powered by the Snapdragon X2 Plus and X2 Elite, offering up to 58% faster graphics performance, 80 TOPS Neural Processing Units (NPUs), and up to 20 hours of battery life. HONOR Robot Phone: The Chinese smartphone maker demoed its mobile photography capabilities by capturing its first cinematic video using the Robot Phone concept, which features a 3-axis, 4DoF gimbal that extends from the phone's body for stable recording and real-time subject tracking. Snapdragon Reality Elite Platform: Qualcomm's new platform is a massive leap forward for mixed reality and spatial computing devices. It can power both all-in-one video-see-through headsets and lightweight, tethered optical-see-through glasses, offering better visuals, improved power efficiency, and deeper on-device AI integration compared to the previous generation. Galaxy XR: Samsung's extended-reality handset arrived in the UK months after its launch. It's available for pre-order now and will go on sale on July 8. The hardware remains unchanged, but Samsung has pushed several new updates in recent months. HONOR Watch 6: HONOR also launched its new smartwatch with an incredible 35-day battery life without breaking your bank. The device is made from recyclable aluminum alloy and weighs just 41 grams. Where are the foldables? If you're waiting for Samsung's fresh lineup of foldable devices, you can read Hamid's detailed post about the Galaxy Z Fold8, Flip8, and Z Fold Wide, a passport-style device expected to rival the foldable iPhone. This week in Google News Image: Google Catch up on some of the latest Google and Alphabet news updates that arrived throughout the week: Gemini co-lead departs: Noam Shazeer, who served as VP of engineering and technical co-lead for Gemini, is leaving the search giant for OpenAI. Shazeer is best known as one of the co-authors of the 2017 "Attention Is All You Need" paper, which introduced the Transformer architecture that now powers most LLMs. Waymo recall: The Alphabet-owned self-driving car maker recalled its fifth-generation Automated Driving Systems (ADS) after multiple cars drove through closed construction zones. The NHTSA website said Waymo is currently working on a fix, and freeway driving is being restricted. This week in Apple News Image: Apple Catch up on some of the latest Apple news updates that arrived throughout the week: Tim Cook confirms price hike: The departing Apple CEO confirmed the looming price hikes for Apple's future products without naming any, adding that “Unfortunately, price increases are unavoidable.” Despite having cash and silicon expertise, Apple has no plans to build its own memory and storage factories. An educated estimate suggests customers could end up paying around $1,299-1,399 for the base iPhone 18 Pro. iPhone Air isn't dead: If you were thinking the iPhone Air has lived its life, a new report claims otherwise. The next iPhone Air (codenamed V62) is expected to arrive in the spring of 2027, featuring an additional rear camera for ultrawide photography and improved battery life to address its biggest drawbacks. This week in Meta news Catch up on some of the latest Meta, WhatsApp, and Instagram updates that arrived throughout the week: A long-requested feature: Instagram has finally enabled users to write individual captions for each image or video in a carousel. Rolling out to all users, you can select "Multiple Captions" option from the dropdown while creating a carousel in the app. Threads reaches new milestone: Meta's text-first social media platform crossed 500 million monthly active users. It's now expanding the Communities feature beyond beta, adding a new set of tools to make participation easier and more engaging. This week in AI news Image via DepositPhotos.com Catch up on the latest artificial intelligence news updates that arrived throughout the week: Unreal Engine 6: Epic Games' upcoming engine brings changes to the programming model, portability improvements, and generative AI integration. It focuses on the use of generative AI models and tools like Claude and Codex to play a central role in helping developers "build content faster." Americans and AI: New research suggests that about 49% of American adults use AI chatbots such as Gemini and ChatGPT. However, many are skeptical about the impact of AI on both the personal and societal levels, believing it may be harmful in the long run. Mainframe exit vendors might exit: Gartner predicts in its new report that 75% of mainframe exit vendors, which help companies migrate their legacy mainframe systems to modern cloud environments, will either pivot or cease operations as the market realities take hold by 2030. This week in Microsoft News Microsoft announced Windows 11 version 26H2; confirmed a new bug where the Recycle Bin delete prompts display internal file names instead of actual ones; the latest Patch Tuesday updates seemingly broke some third-party Office integrations. You can check out Taras's freshly baked Microsoft Weekly roundup to catch up on all the interesting stories this week. This week in science news Image by Steve Johnson via Pexels Catch up on some of the latest science and out-of-this-world updates that arrived throughout the week: The end of the universe: A new Cornell study suggests the universe will not expand forever. Because of the negative dark energy, it could stop expanding and collapse into a "big crunch" in 20 billion years. The impact of traffic: Researchers found that urban traffic pollution, specifically nitrogen oxides and fine particles, quickly alters the atmospheric electric field measurably in urban areas. This indicates that atmospheric electricity could become a valuable tool to monitor urban air quality and activity. The light of life: A study revealed that living organisms emit a faint, invisible glow called ultraweek photon emission. This natural light significantly decreases after death and increases during stress, offering a highly promising new method for noninvasive medical health diagnosis. Mysteries of time: A new study suggests that the direction of time is not fixed in certain quantum systems. Standard equations of energy loss remain time-symmetric, which means laws can theoretically run backward or forward. This week in gaming The latest issue of Pulasthi's Weekend PC Game Deals curates several exciting games on sale this week. Epic Games Store is now hosting Robobeat and Citizen Sleeper as free-to-claim titles this week, which you can add to your library. Latest issue of Xbox Free Play Days features four new games: PGA TOUR 2K25, Two Point Museum, Assetto Corsa, and Dead by Daylight. Meanwhile, Xbox Game Pass got another Call of Duty addition, the latest soccer game from EA, an indie road trip hit from last year, and more. Summer sales have made NVIDIA's gaming service cheaper, and it has added support for seven new titles. That said, here are some more stories from the gaming world: Rockstar gives last-gen GTA V players free upgrades tomorrow Major Xbox layoffs may claim South of Midnight developer Compulsion entirely Steam Next Fest returns with thousands of new demos to try out Forza Horizon 6 gets another hotfix for one of the game's online modes Major Xbox layoffs may claim South of Midnight developer Compulsion entirely From the review corner This week, Steven got his hands on the Creative Sound Blaster AE-X internal PCIe sound card, primarily intended for headphone wearers. In the list of pros, it comes with a high-quality headphone amp, low-latency communication enhancements via ASIO v2.3, offers 256-times the audio quality of CDs via DSD256, and has great build quality. On the other hand, it's a bit on the pricier side, only offers stereo output over speakers, and has no EMI shielding. More price drops! We got you covered with some hot tech deals all week. For some reason, if you missed out on a great discount, here is a summary of some recent deals that are still alive: GEEKOM X16 Pro at GEEKOM - $1,119.67 (17% off) Acer 4K Webcam for PC/Mac with All-Metal Unibody Sculpted - $59.99 (14% off) Samsung 990 PRO SSD 2TB - $369.99 (42% off) Nothing Ear Wireless Earbuds Bluetooth - $73.15 (51% off) PowerColor Reaper AMD Radeon RX 9070 16GB - $579.99 (17% off) To view all of our recent deals, click here. So, these were some of the biggest tech news and other updates from this week. There will be more issues of our 7 Days series in the coming weeks and months, so stay tuned. You can also support Neowin by registering for a free member account or subscribing to extra member benefits, along with an ad-free tier option. Have a great weekend!
  • Recent Achievements

    • Dedicated
      Almohandis earned a badge
      Dedicated
    • Dedicated
      JuvenileDelinquent earned a badge
      Dedicated
    • First Post
      DrWankel earned a badge
      First Post
    • Reacting Well
      DrWankel earned a badge
      Reacting Well
    • Week One Done
      Supreme Spray LV earned a badge
      Week One Done
  • Popular Contributors

    1. 1
      +primortal
      507
    2. 2
      +Edouard
      185
    3. 3
      PsYcHoKiLLa
      84
    4. 4
      Michael Scrip
      78
    5. 5
      Steven P.
      75
  • Tell a friend

    Love Neowin? Tell a friend!