![](/img/trans.png)
[英]WinForms: How to fix incorrect scaling of Forms in high-DPI, multi-monitor environments (PerMonitorV2) with different resolution/scaling
[英]ContextMenuStrip doesn't DPI scale when Form is dragged between monitors with different resolution/scaling (WinForms, .NET 6.0, PerMonitorV2)
蠻力解決方案是在每次顯示ContextMenuStrip時重新生成它。 一個可能較低開銷但仍然不優雅的解決方案是在DpiChanged事件上重新生成ContextMenuStrip ,如下所示。 在ContextMenuStrip上調用Refresh()、PerformLayout()或Invalidate()似乎不足以強制它進行縮放。 但是即使沒有重新生成菜單項,生成一個新的ContextMenuStrip似乎也會強制重新縮放。
private void Form1_DpiChanged(object sender, DpiChangedEventArgs e)
{
this.ContextMenuStrip = new ContextMenuStrip(components);
this.ContextMenuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.menu1ToolStripMenuItem,
this.menu2ToolStripMenuItem});
}
有比這更清潔的解決方案嗎?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.