dotnet / winforms

Windows Forms is a .NET UI framework for building Windows desktop applications.
MIT License
4.29k stars 957 forks source link

ContextMenuStrip show on wrong monitor #11289

Open osexpert opened 2 months ago

osexpert commented 2 months ago

.NET version

dotnet8

Did it work in .NET Framework?

Not tested/verified

Did it work in any of the earlier releases of .NET Core or .NET 5+?

No idea. I had to switch to ContextMenuStrip because ContextMenu was removed in dotnet6. It may never have worked correctly.

Issue description

In dotnet 8, create a new WinForms project. Add a ContextMenuStrip on the Form. In the Form mouse click event, do this: private void Form1_MouseClick(object sender, MouseEventArgs e) { contextMenuStrip1.Show(this, e.Location); } Use 2 monitors. Run app, maximize app\form on first (left) monitor. Click on form close to the right edge of first (left) monitor. Notice the context menu is showing on the second (right) monitor. This is not very user friendly! Also, ContextMenu that was removed in WinForms for dotnet6 did not have this problem.

Steps to reproduce

Info in Issue description

osexpert commented 2 months ago

Seems to be a known problem for over 9 years: https://stackoverflow.com/questions/26587843/prevent-toolstripmenuitems-from-jumping-to-second-screen/78399012#78399012 I wish you did not remove ContextMenu when the alternative is given so little TLC.

elachlan commented 2 months ago

@Olina-Zhang can your team please test this?

@osexpert are both the monitors at normal DPI?

Philip-Wang01 commented 2 months ago

@elachlan Here are the test results:

  1. This is not a regression issue, it can be reproduced in .NET framework and .NET 6.0 - 9.0.
  2. The ContextMenu control does not reproduce the issue.
  3. This issue only reproduces when the DPI of the primary screen is less than or equal to the DPI of the secondary screen. The issue does not reproduce when the primary screen DPI is greater than the secondary screen DPI.
  4. Using PerMonitorV2 mode does not solve the problem.

https://github.com/dotnet/winforms/assets/86937911/a54ed7d5-7bef-4f86-a6d7-281a4e4e8279

elachlan commented 2 months ago

Fantastic analysis! Thanks!

merriemcgaw commented 2 months ago

This is not a regression, and it doesn't meet the bar for the team to address in .NET 9 given current priorities. We, of course, wouldn't say no to a community contribution that addresses the issue!

dotnet-policy-service[bot] commented 2 months ago

This issue is now marked as "help wanted", and we’re looking for a community volunteer to work on this issue. If we receive no interest in 180 days, we will close the issue. To learn more about how we handle feature requests, please see our documentation.

Happy Coding!