Solved

detecting screen resolution in VB.NET

Posted on 2002-05-17
5
377 Views
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.

Thanks
0
Comment
Question by:tbbrhun
  • 3
  • 2
5 Comments
 
LVL 4

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_Sub:
    Exit Function
   
Syntax_Error:
    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
Steve
0
 

Author Comment

by:tbbrhun
ID: 7017213
I'm looking for VB.NET solution to this problem. THANKS!
0
 
LVL 4

Expert Comment

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

Accepted Solution

by:
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 = _
        System.Windows.Forms.Screen.AllScreens
    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())

    Next

And yes this is .NET code

Good luck
Steve
0
 

Author Comment

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

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

744 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now