简体   繁体   中英

Secondary dropdown menu arrow symbol drawn at wrong size on screen with different DPI/scaling (WinForms)

If a WinForms app is dragged from a screen with high scaling to one with lower scaling, the arrow designating a secondary menu pulldown is displayed with incorrect scaling. Once the menu is opened while the form is on the high scaling screen, then the arrow is displayed at the correct size on all screens from that point forward. The issue seems to exist both in.Net Framework 4.8 and .NET 6.0.

Here's a picture of the oversized arrow:

在菜单中显示超大箭头的图像

Does anyone know a good work-around to this issue?

This is pretty ugly, but seems to solve the issue in all cases I have tried so far. Just calling ShowDropDown() did not fix the issue. But calling ShowDropDown() followed by DoEvents() before the form is shown corrects the problem:

public Form1()
    {
    this.Font = SystemFonts.IconTitleFont;
    InitializeComponent();

    // Show the file menu momentarily to fix arrow scaling issue

    fileToolStripMenuItem.ShowDropDown();
    Application.DoEvents();
    }

Or in Shown() :

private void Form1_Shown(object sender, EventArgs e)
    {
    fileToolStripMenuItem.ShowDropDown();
    Application.DoEvents();
    fileToolStripMenuItem.HideDropDown();
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM