【VB.NET】ディスプレイの情報を取得する方法
Screen.PrimaryScreenプロパティを確認することにより、ディスプレイの情報を取得できます。
ディスプレイが1つまたは、メインディスプレイの情報
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
'ディスプレイの高さ
Dim h As Integer = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height
'ディスプレイの幅
Dim w As Integer = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width
'ディスプレイのサイズ
Dim s As Drawing.Size = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Size
'結果表示
Console.WriteLine("ディスプレイの高さ:{0}ピクセル", h)
Console.WriteLine("ディスプレイの幅:{0}ピクセル", w)
Console.WriteLine("ディスプレイのサイズ{0}", s)
End Sub
End Class
全てのディスプレイの情報
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
For i = 0 To System.Windows.Forms.Screen.AllScreens.Count - 1
'処理内容(何回も処理される)
'主ディスプレイであるかどうか?
Dim p As Boolean = System.Windows.Forms.Screen.AllScreens(i).Primary
'ディスプレイのデバイス名
Dim n As String = System.Windows.Forms.Screen.AllScreens(i).DeviceName
'ディスプレイの高さ
Dim h As Integer = System.Windows.Forms.Screen.AllScreens(i).Bounds.Height
'ディスプレイの幅
Dim w As Integer = System.Windows.Forms.Screen.AllScreens(i).Bounds.Width
'ディスプレイのサイズ
Dim s As Drawing.Size = System.Windows.Forms.Screen.AllScreens(i).Bounds.Size
'結果表示
Console.WriteLine("主ディスプレイであるかどうか?:{0}", p)
Console.WriteLine("デバイス名:{0}", n)
Console.WriteLine("ディスプレイの高さ:{0}ピクセル", h)
Console.WriteLine("ディスプレイの幅:{0}ピクセル", w)
Console.WriteLine("ディスプレイのサイズ{0}", s)
Next
End Sub
End Class
Formのあるディスプレイの情報
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
'ディスプレイのサイズ
Dim s As Drawing.Size = System.Windows.Forms.Screen.GetBounds(Me).Size
Console.WriteLine("ディスプレイのサイズ{0}", s)
End Sub
End Class


コメント