winforms
winforms copied to clipboard
ContextMenuStrip show on wrong monitor
.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
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.
@Olina-Zhang can your team please test this?
@osexpert are both the monitors at normal DPI?
@elachlan Here are the test results:
- This is not a regression issue, it can be reproduced in .NET framework and .NET 6.0 - 9.0.
- The ContextMenu control does not reproduce the issue.
- 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.
- Using PerMonitorV2 mode does not solve the problem.
https://github.com/dotnet/winforms/assets/86937911/a54ed7d5-7bef-4f86-a6d7-281a4e4e8279
Fantastic analysis! Thanks!
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!
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!