ContextMenuStrip doesn't scale well for its menu item's checked icon.
Environment
Visual Studio 2022 17.2.6
.NET version
.NET6.0
Did this work in a previous version of Visual Studio and/or previous .NET release?
have not tested any previous version
Issue description
200% dpi, 4k screen
a demo, only have two controls: ContextMenuStrip and MenuStrip, add random menuitem for them.
The issue is that the vertical panel is too narrow for the checked icon in ContextMenuStrip, as a contrast, the MenuStrip is normal.
Steps to reproduce
- create a WinForm app.
- add a ContextMenuStrip control and a MenuStrip control from toolbox
- add some menu item for them
- set check state of one menu item to true
- run app
Diagnostics
No response
Duplicate of #9044. @Olina-Zhang, can you confirm it with .Net 8.0 and close this?
Verified this issue in the latest .Net 8.0 SDK build: 8.0.100-preview.6.23313.16 on HDPI machine(200% dpi, 4k screen), this issue is repro and it is different from issue: #9044 . Note: The issue is that the vertical panel is too narrow for the checked icon in ContextMenuStrip, as a contrast, the MenuStrip is normal. Please see the test results:
Attach test project:
WinFormsApp12.zip
Thanks @Ashley-Li for the updated info.
Also reproduceable on .NET Framework 4.8. Note that, unlike the margin of the parent dropdown, the margin of the child dropdown does scale up without issue.
As for .NET 8, I have also tested ContextMenuStrip on the latest 8.0.204 and the same scaling issue is still observed.
| 96 DPI (100%) | 120 DPI (125%) |
|---|---|
| 144 DPI (150%) | 168 DPI (175%) |
|---|---|
[!IMPORTANT]
This issue is only reproduceable whenPerMonitorV2DPI awareness is specified inapp.config.
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<System.Windows.Forms.ApplicationConfigurationSection>
<add key="DpiAwareness" value="PerMonitorV2" />
</System.Windows.Forms.ApplicationConfigurationSection>
</configuration>
I am seeing this issue but with a slightly different end result. Here is a screenshot from 150%/144 DPI:
When my application lacks DPI awareness, the check image looks fine. When DPI awareness is enabled, the check image is scaled, but the check margin/check background are not.
I believe this is because the constructors for ContextMenuStrip only call the default constructor for the base ToolStripDropDownMenu. The default constructor calls ScaleConstants(ScaleHelper.OneHundredPercentLogicalDpi), but the one taking arguments calls ScaleConstants(ScaleHelper.InitialSystemDpi). The size of the check background comes from _defaultImageSize, which is scaled or not scaled there. Nested menus work normally because adding items via ToolStripMenuItem.DropDownItems eventually calls through to ToolStripMenuItem.CreateDefaultDropDown, which creates a ToolStripDropDownMenu using the constructor with parameters.