I have a C# Windows Forms application that was written and originally tested on Windows 10. The application needs to be able to open on any given monitor (set via a config file), and this feature works fine on Windows 10. To prepare for future system requirements, we have been preparing a Windows 11 image and trying to test software on Windows 11 to verify operation, and in doing so, we are running into an issue where this C# program will not load correctly on any monitor that is not set in Windows 11 as the "main display".
By "not load correctly", I mean that ONLY the title bar (the bar that gives the icon, title of the window, and the minimize, maximize, and close buttons) will load, and the actual body of the application will not load, even after waiting several minutes. Trying to interact with this title bar results in the application hanging and becoming unresponsive, but it can be closed without issue by right clicking the icon for the application in the taskbar and selecting the option to close the application.
To reiterate, the application opens correctly, and seems to operate without issue, on the main display as set in Windows 11, but any other display results in the abovementioned issue. How would I go about either solving this issue (i.e., making the application work so that it loads correctly on any monitor) or go about finding the cause of the issue (i.e., finding the underlying settings/root causes of the error)?
Changing the monitor that the application should open on via the config file works correctly, as the title bar will appear on the monitor that was set. Changing the main display allows the program to open correctly on that screen, but then the same issue occurs on the old main display (the one before the change).
Changing the program to only operate on the main display is not an option for our system needs.
Additional details:
We have tried the following to find a solution:
None of these attempts seemed to at all affect the overall operation of the application or whether it would function correctly or not.
I have found the answer, for anyone curious.
I was correct in that the issue was not with my code but with Windows 11, apparently there is something weird in how Windows 11 deals with the Win32 API SetWindowPos function. I fixed the problem by removing that function and instead using the MoveWindow function from the same API. I tested this today and verified it works on both Windows 10 and Windows 11. If anyone comes across the same issue, this would be a good place to start troubleshooting.