December 5, 1995
This article explains how to determine the current screen resolution in a Microsoft® Visual Basic® application.
When developing a Microsoft® Visual Basic® application, it may be necessary to determine the current screen resolution. You can do this by retrieving the TwipsPerPixelX and TwipsPerPixelY properties of the Screen object.
To determine the horizontal resolution of the screen, you retrieve the value of the TwipsPerPixelX property. Next, you divide the screen's current Height property by this value.
To determine the vertical resolution of the screen, you retrieve the value of the TwipsPerPixelY property. Next, you divide the screen's current Width property by this value.
This program shows how to determine the current screen resolution in a Visual Basic application.
Private Sub Command1_Click()
Dim XTwips As Long
Dim YTwips As Long
Dim XPixels As Long
Dim YPixels As Long
XTwips = Screen.TwipsPerPixelX
YTwips = Screen.TwipsPerPixelY
YPixels = Screen.Height / YTwips
XPixels = Screen.Width / XTwips
Text1.Text = Str$(XPixels) + " x " + Str$(YPixels)
End Sub
Run the example program by pressing f5. Click the Command Button control. The current screen resolution appears in the Text Box control.