2014-02-28 216 views
-3

是否有任何實現的代碼來獲得屏幕分辨率?獲取屏幕分辨率

我想製作一個程序,它可以針對不同的屏幕分辨率工作。

+0

HTTP: //msdn.microsoft.com/en-us/library/system.windows.forms.screen%28v=vs.110%29.aspx –

回答

2

只要執行以下操作,它已經內置到框架中。

Dim screenWidth as Integer = Screen.PrimaryScreen.Bounds.Width 
Dim screenHeight as Integer = Screen.PrimaryScreen.Bounds.Height 

請注意,在問之前,研究。這已經被回答,並發現一個快速谷歌搜索 - Getting Screen Resolution

0

我的解決方案也將努力爲擴展桌面(雙屏幕)

''' <summary> 
''' Gets the extended screen resolution (for Dual-Screens). 
''' </summary> 
Private Function GetExtendedScreenResolution() As Point 

    Dim ResX As Integer = 
     (From scr As Screen In Screen.AllScreens Select scr.Bounds.Width).Sum 

    Dim ResY As Integer = 
     (From scr As Screen In Screen.AllScreens Select scr.Bounds.Height).Sum 

    Return New Point(ResX, ResY) 

End Function 

''' <summary> 
''' Gets the primary screen resolution. 
''' </summary> 
Private Function GetPrimaryScreenResolution() As Point 

    Return New Point(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height) 

End Function 

應用實例:

' Usage Examples: 
MsgBox(GetExtendedScreenResolution.ToString) 
Dim Resolution as Point = GetExtendedScreenResolution() 
Me.Size = GetPrimaryScreenResolution()