检测表单必须加载VB.net的屏幕最终使用的屏幕数

时间:2016-03-16 22:31:10

标签: vb.net

我在网上搜索过,在以下问题上找不到多少:

  1. 我怎么能用vb.net检测到我有多少个屏幕(以及它们有哪些分辨率)。
  2. 我如何发送识别监控命令(知道每个屏幕有哪个号码)
  3. 我如何(检测后)选择我的表格必须在哪个屏幕上打开?
  4. 有人能帮助我吗?

    在我的情况下,我有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
    

1 个答案:

答案 0 :(得分:1)

PrimaryScreenAllScreens属性为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

这应该说明如何命名屏幕,以及如何确定哪个是哪个,以及如何在特定屏幕上定位表单。我刚刚在我的四显示器设置上测试了它,它的表现与预期一致。