我在网上搜索过,在以下问题上找不到多少:
有人能帮助我吗?
在我的情况下,我有4个屏幕,但我必须从主屏幕中选择我想要加载第二个表格的屏幕。
我在网上发现了这个但是没有检测到任何屏幕:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim form As New Form
Dim screen As Screen
' We want to display a form on screen 1
screen = screen.AllScreens(1)
' Set the StartPosition to Manual otherwise the system will assign an automatic start position
form.StartPosition = FormStartPosition.Manual
' Set the form location so it appears at Location (100, 100) on the screen 1
form.Location = screen.Bounds.Location + new Point(100, 100)
' Show the form
form.ShowDialog(Me)
End Sub
答案 0 :(得分:1)
PrimaryScreen
和AllScreens
属性为Shared
,因此您可以在Screen
类上访问它们,而不是Screen
类的实例。看看这段代码:
Dim primaryScreen = Screen.PrimaryScreen
Dim allScreens = Screen.AllScreens
For Each screen In allScreens
Dim location = Point.Add(screen.Bounds.Location, New Size(100, 100))
Dim text = screen.DeviceName
If screen Is primaryScreen Then
text &= " (Primary)"
End If
Using dialogue As New Form With {.Text = text,
.StartPosition = FormStartPosition.Manual,
.Location = location}
dialogue.ShowDialog()
End Using
Next
这应该说明如何命名屏幕,以及如何确定哪个是哪个,以及如何在特定屏幕上定位表单。我刚刚在我的四显示器设置上测试了它,它的表现与预期一致。