Winforms screen dimming overlay program gets drawn twice when opening/closing start menu or context menu's in taskbar

XiaoYiHu-6776 0 Reputation points
2024-02-12T16:10:45.87+00:00

I'm currently making a screen dimming program in C# that uses black winform forms with an adjustable opacity to dim the whole display. This by itself is unable to dim certain windows UI elements such as the start menu, alt+tab and win+tab menus. In order to be able to dim these menus I've declared the program to be accessibility as described in the top answer in this stack overflow post. My program is currently:

  1. Declaring level="requireAdministrator" and uiAccess="true" in app.manifest.
  2. Calling topmost = true; in my overlay forms.
  3. Signed using a self-signed certificate.
  4. Running from Program Files.

By doing all this my program is now able to draw on top of the previously undimmed menu's. However, when opening and closing the start menu and context menus in the taskbar, switching virtual desktops using win+ctrl+left/right arrow, everything outside that windows UI element get dimmed twice until the UI animation finishes. I'm assuming windows draws the overlay form twice during the UI animations, once underneath the windows menu elements and once above. Is there any way to prevent this behavior?

Windows Forms
Windows Forms
A set of .NET Framework managed libraries for developing graphical user interfaces.
1,873 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,650 questions
{count} votes