vb.net 如果存在第二个监视器屏幕,则移动表单
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/31592823/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Move Form if second monitor screen exists
提问by InProgess
Looking for a way to load a from if a second screen exists.
如果存在第二个屏幕,则寻找一种从中加载 a 的方法。
I have tried this code with a load event:
我已经用加载事件尝试了这段代码:
Dim numofMon As Integer = Screen.AllScreens.Length
If numofMon > 1 Then
Me.Bounds = Screen.AllScreens(1).Bounds
End If
Side note: If someone could point me to how to detect when the cursor is no longer on the form, I would appreciate it.
旁注:如果有人能指出我如何检测光标何时不再位于表单上,我将不胜感激。
回答by InProgess
This ended up working for me.
这最终对我有用。
Dim obj as New Form2
obj.Location = Screen.AllScreens(UBound(Screen.Allscreens)).Bounds.Location
obj.show()
回答by Saragis
To be able to place the form on the second screen, set the WindowStartUpLocationto Manual before setting the Bounds. This causes the form to be positioned according to its Left and Top property values. These will then be set by changing the Bounds property as you already did.
为了能够将表单放置在第二个屏幕上,请在设置边界之前将WindowStartUpLocation设置为手动。这会导致窗体根据其 Left 和 Top 属性值进行定位。然后将通过像您一样更改 Bounds 属性来设置这些。
To detect if the cursor is above the form that's currently focused, use the MouseEnterand MouseLeaveevents.
要检测光标是否位于当前聚焦的窗体上方,请使用MouseEnter和MouseLeave事件。

