.Net/Winforms, Dual monitor - Borderless Window - Maximizing doesn't work

ぃ、小莉子 提交于 2019-12-23 02:07:10

问题


I have a question that were not answered on

http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/fa521007-f317-48f1-9cdd-de2dbcb17aa8

(last posts are my posts). StackOverflow is better forum so could you help me :)

Briefly:

  • dual monitor configuration, primary monitor on right has lower resolution, on left side monitor with higher resolution (lo: 1280x1024; hi: 1680x1050). When maximizing on bigger one, window is larger than monitor (works only on left monitor)
  • working on a borderless window base class
  • maximize to the actual client area does not work as expected. Solved by adding a WndProc hook and fiddling with the size parameters. Multiple monitor support added some issues, because maximizing seems to rely on MaxTrackSize instead of MaxSize. This seems to happen only when the primary monitor is smaller than the second monitor

Something I found in specification:

http://msdn.microsoft.com/en-us/library/ms632605(v=VS.85).aspx

For systems with multiple monitors, the ptMaxSize and ptMaxPosition members describe the maximized size and position of the window on the primary monitor, even if the window ultimately maximizes onto a secondary monitor. In that case, the window manager adjusts these values to compensate for differences between the primary monitor and the monitor that displays the window. Thus, if the user leaves ptMaxSize untouched, a window on a monitor larger than the primary monitor maximizes to the size of the larger monitor.

So if I understand correctly in my case it is impossible to maximize on screen with higher resolution when there is taskbar placed in the way not to hide it under maximized window?

Cheers, jbk


回答1:


You can implement your own "maximize":

  1. Determine which screen your form resides on with Screen.FromControl
  2. Set the offset and size of your Formaccording to the screen's offset and size.
  3. You can use either use the WorkingArea(the desktop area) or the Bounds(the whole screen with the toolbars) of the Screen as required.

*If you want to hide the toolbars and be defacto "full screen", i think you will need to set the form as TopMost.




回答2:


This is what worked for me:

  1. Set FormBorderStyle to FixedSingle - might also work with other styles != None, haven't tested that...
  2. Set WindowState to FormWindowState.Maximized
  3. Reset FormBorderStyle to None

At least, it works for pure WinForms stuff without resorting to WinAPI



来源:https://stackoverflow.com/questions/4427036/net-winforms-dual-monitor-borderless-window-maximizing-doesnt-work

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!