Library code snippets

Screen Resolution

This code snippet will allow you to fetch the screen resolution. Put the code in the button named btnResol and see.

Private Sub btnResol_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnResol.Click

MessageBox.Show (System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width())
MessageBox.Show (System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height())

End Sub

Comments

  1. 10 Aug 2004 at 02:11

    Hi! Fortius


    I too have same problem of "workingarea.height" showing less 28 pixels. This due to the Task Bar. If u hide it and access the "workingarea.height" then it shows 600 pixels (for screen resolution 800 x 600).


    Also if u try this code the Bound property of Screen will fetch you the exact pixels irrespective of Taskbar state.


    ' Code from MSDN
      Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
           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
       End Sub

  2. 28 Jun 2004 at 05:59

    hey, this code isn't working prefectly (at least not at my side) ... the height returned by "workingarea.height" is always 28 pixels less than the original resolution for e.g. 800 X 600 is returned as 800 X 572 - 1024 X 768 is returned as 1024 X 740 .... anyways i found the work around .. instead of using WorkingArea.XX methods use "Bounds" method to get the exact figure.


           Dim xBounds As Rectangle = System.Windows.Forms.Screen.PrimaryScreen.Bounds


           Label1.Text = xBounds.Width & " X " & xBounds.Height


    plus if anybody knows how to change the screen resolution pls. reply me, i would be highly g8ful.


    Regards,
    Fortius.

  3. 01 Jan 1999 at 00:00

    This thread is for discussions of Screen Resolution.

Leave a comment

Sign in or Join us (it's free).

AddThis

Related jobs

Events coming up

  • Dec 6

    Developing AJAX Web Applications with Castle Monorail

    London, United Kingdom

    Monorail is the model-view-controller engine of the Castle Project, bringing many of the best ideas of Ruby on Rails to the .NET world. In this talk, David De Florinier and Gojko Adzic show how Monorail makes it easy to develop .NET based AJAX applications, and how to use the Castle Project to build Web 2.0 applications effectively. Come to this session if you are a .NET web developer. Everyone is welcome!