Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to check the screen resolution in vb.net?

45 views
Skip to first unread message

Ivan

unread,
May 29, 2002, 10:35:04 PM5/29/02
to
Would you know how to check the screen resolution in vb.net?

In VB 6:

Public Declare Function GetSystemMetrics Lib "user32.dll" (ByVal nIndex As
Long) As Long

Public Const SM_CXSCREEN = 0
Public Const SM_CYSCREEN = 1

Public Function HaveRez(ByVal lngpixelW As Long, lngpixelH As Long) As
Boolean
Dim lngTwipsX As Long, lngTwipsY As Long

HaveRez = False
lngTwipsX = GetSystemMetrics(SM_CXSCREEN)
lngTwipsY = GetSystemMetrics(SM_CYSCREEN)
If lngTwipsX >= lngpixelW And lngTwipsY >= lngpixelH Then
HaveRez = True
End If
End Function


Vlad

unread,
May 29, 2002, 10:48:48 PM5/29/02
to
I'm working on resolution independent version of VB.Net application and
using this approach:
Public Sub GetMultiplier()
Dim intScreenResolution
Dim frm As New Form()
Dim rct As New Rectangle()
rct = Screen.GetBounds(frm)
frm.Close()
If rct.Width = 800 And rct.Height = 600 Then
intScreenResolution = 1
ElseIf rct.Width = 1024 And rct.Height = 768 Then
intScreenResolution = 2
ElseIf rct.Width = 1152 And rct.Height = 864 Then
intScreenResolution = 3
ElseIf rct.Width = 1280 And rct.Height = 960 Then
intScreenResolution = 4
ElseIf rct.Width = 1600 And rct.Height = 1200 Then
intScreenResolution = 5
Else 'All other not supported resolutions.
intScreenResolution = 0
End If

'Then I use intScreenResolution to return multiplier from Select Case. It
will be used to resize and reposition controls on all forms in my
application.
Vlad


"Ivan" <firez...@nil.vv> wrote in message
news:OtVlBK4BCHA.2688@tkmsftngp05...

Rohit Chaphekar

unread,
May 30, 2002, 1:36:00 AM5/30/02
to
You can use
dim ScreenPixelWidth() As Short

ScreenPixelWidth =
VB6.PixelsToTwipsX(System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width) \
VB6.TwipsPerPixelX

dim ScreenPixelHeight() As Short

ScreenPixelHeight =
VB6.PixelsToTwipsY(System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height)
\ VB6.TwipsPerPixelY

Hope this helps

Rohit

"Vlad" <v.ch...@verizon.net> wrote in message
news:eWPNuR4BCHA.2596@tkmsftngp05...

Ivan

unread,
May 30, 2002, 7:55:22 PM5/30/02
to
Thanks!
"Vlad" <v.ch...@verizon.net> 撰寫於郵件新聞
:eWPNuR4BCHA.2596@tkmsftngp05...

Ivan

unread,
May 30, 2002, 7:56:14 PM5/30/02
to
Thanks a lot!
"Rohit Chaphekar" <smar...@hotmail.com> 撰寫於郵件新聞
:OpHrIv5BCHA.2464@tkmsftngp05...

Christopher M. Piper

unread,
May 30, 2002, 8:26:58 PM5/30/02
to
How About:

Dim XRes As Short = _
System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width
Dim YRes As Short = _
System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height
Debug.WriteLine("The Screen Resolution is " & Xres & "x" & YRes & ".")

You'd be surprised all you can find in the .NET Framework that really is
usefull.

Christopher M. Piper


"Ivan" <firez...@nil.vv> wrote in message

news:uVua7VDCCHA.2540@tkmsftngp05...

0 new messages