Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

detecting screen resolution in VB.NET

Posted on 2002-05-17
5
Medium Priority
?
409 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 200 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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…
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

886 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