winforms icon indicating copy to clipboard operation
winforms copied to clipboard

ContextMenuStrip show on wrong monitor

Open osexpert opened this issue 9 months ago • 6 comments

.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 avatar Apr 28 '24 17:04 osexpert

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.

osexpert avatar Apr 28 '24 17:04 osexpert

@Olina-Zhang can your team please test this?

@osexpert are both the monitors at normal DPI?

elachlan avatar Apr 29 '24 02:04 elachlan

@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

Philip-Wang01 avatar Apr 29 '24 07:04 Philip-Wang01

Fantastic analysis! Thanks!

elachlan avatar Apr 29 '24 08:04 elachlan

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!

merriemcgaw avatar Apr 30 '24 18:04 merriemcgaw

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!