使用两个显示器获取屏幕尺寸

时间:2014-03-10 15:32:18

标签: vb.net

我使用此代码获取屏幕尺寸的高度:

 Dim hdcSrc As IntPtr = User32.GetWindowDC(handle)       
 Dim windowRect As New User32.RECT
 User32.GetWindowRect(handle, windowRect)
 Dim width As Integer = windowRect.right - windowRect.left
 Dim height As Integer = windowRect.bottom - windowRect.top

现在,当我们有两台不同尺寸的显示器时。哪个被认为是默认监视器?

2 个答案:

答案 0 :(得分:2)

Net Framework中有一个很有用的类可以轻松替换您的代码。

Screen class

使用

获取主屏幕
Screen.PrimaryScreen

例如,上面的代码可以使用

替换
Dim area As Rectangle = Screen.PrimaryScreen.Bounds
Console.WriteLine("Width: " & area.Width.ToString)
Console.WriteLine("Height: " & area.Height.ToString)

答案 1 :(得分:0)

所有这些都可以在Screen课程中找到:

Screen.AllScreens

Screen.PrimaryScreen
相关问题