detecting screen resolution in VB.NET

Posted on 2002-05-17
Last Modified: 2007-12-19
I'd like to find a VB.NET library containing the object that would allow me to detect screen resolution in VB.NET. I'd like to do it with a native VB.NET method, not via VB6 compatibility.

Question by:tbbrhun
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2

Expert Comment

by:Steve Sirica
ID: 7017175
here's what I use:
Public Function gsChkScreenRes()
    Dim XTwips      As Long
    Dim YTwips      As Long
    Dim XPixels     As Long
    Dim YPixels     As Long
    On Error GoTo Syntax_Error
    XTwips = Screen.TwipsPerPixelX
    YTwips = Screen.TwipsPerPixelY

    XPixels = Screen.Height / YTwips
    YPixels = Screen.Width / XTwips
    gsChkScreenRes = YPixels * XPixels

    Exit Function
    Resume Exit_Sub
End Function
if it returns <= Mode1 then it's 640x480 and so on.

    'Numbers of Colors in palette
    Const Mode1 = 307200    '* 640 x 480
    Const Mode2 = 480000    '* 800 x 600
    Const Mode3 = 786432    '* 1024 x 768
you can add what you need to check

Good luck

Author Comment

ID: 7017213
I'm looking for VB.NET solution to this problem. THANKS!

Expert Comment

by:Steve Sirica
ID: 7017221
I didn't see that, sorry.

Accepted Solution

Steve Sirica earned 50 total points
ID: 7017245
See if there's anythying in here that will help you:

    Dim Index As Integer
    Dim UpperBound As Integer

    ' Gets an array of all the screens connected to the system.

    Dim Screens() As System.Windows.Forms.Screen = _
    UpperBound = Screens.GetUpperBound(0)

    For Index = 0 To UpperBound

        ' For each screen, add the screen properties to a list box.

        ListBox1.Items.Add("Device Name: " + Screens(Index).DeviceName)
        ListBox1.Items.Add("Bounds: " + Screens(Index).Bounds.ToString())
        ListBox1.Items.Add("Type: " + Screens(Index).GetType().ToString())
        ListBox1.Items.Add("Working Area: " + Screens(Index).WorkingArea.ToString())
        ListBox1.Items.Add("Primary Screen: " + Screens(Index).Primary.ToString())


And yes this is .NET code

Good luck

Author Comment

ID: 7017278
Excellent! THANKS! I can take from here now. THANKS AGAIN!

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month7 days, 12 hours left to enroll

632 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question