winforms icon indicating copy to clipboard operation
winforms copied to clipboard

ContextMenuStrip doesn't scale well for its menu item's checked icon.

Open staycool opened this issue 2 years ago • 5 comments

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

Steps to reproduce

  1. create a WinForm app.
  2. add a ContextMenuStrip control and a MenuStrip control from toolbox
  3. add some menu item for them
  4. set check state of one menu item to true
  5. run app

Diagnostics

No response

staycool avatar Jun 09 '23 05:06 staycool

Duplicate of #9044. @Olina-Zhang, can you confirm it with .Net 8.0 and close this?

dreddy-work avatar Jun 13 '23 19:06 dreddy-work

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:
contextMenuStrip menustrip Attach test project: WinFormsApp12.zip

Ashley-Li avatar Jun 14 '23 06:06 Ashley-Li

Thanks @Ashley-Li for the updated info.

dreddy-work avatar Jun 14 '23 16:06 dreddy-work

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%)
image image
144 DPI (150%) 168 DPI (175%)
image image

[!IMPORTANT]
This issue is only reproduceable when PerMonitorV2 DPI awareness is specified in app.config.

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <System.Windows.Forms.ApplicationConfigurationSection>
        <add key="DpiAwareness" value="PerMonitorV2" />
    </System.Windows.Forms.ApplicationConfigurationSection>
</configuration>

xv avatar May 08 '24 05:05 xv

I am seeing this issue but with a slightly different end result. Here is a screenshot from 150%/144 DPI:

dpi example

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.

nrs-mparker avatar May 10 '24 18:05 nrs-mparker