Results 1 to 5 of 5

Thread: [RESOLVED] Getting the screen area in VB.Net

  1. #1

    Thread Starter
    Fanatic Member InvisibleDuncan's Avatar
    Join Date
    May 2001
    Location
    Eating jam.
    Posts
    819

    Resolved [RESOLVED] Getting the screen area in VB.Net

    Our users like to have their forms open up in the same place each time they use them (i.e. so that they open up in the position they were in when they were previously closed), so we store the location of each form when they close it, and re-apply that location each time they open it. Easy.

    However, we have a problem with some users who sometimes use one monitor, and sometimes use two - there have been instances where they closed a form while it was on their second (right-hand) monitor and then try to open it on a laptop with only one screen... and it sticks the form out of sight to the right.

    I can get around this easily on the VB6 forms by using:

    SystemParametersInfo(SPI_GETWORKAREA, vbNull, pRect, 0)

    ... to determine how big the screen they're currently using is, and overriding their settings if it would otherwise mean the form being out of sight. However, I can't get it to work in VB.Net - the RECT structure always returns 0 for all positions. So, does anyone know how to get the screen size using VB.Net?

    Thanks...
    Last edited by InvisibleDuncan; Dec 6th, 2007 at 04:09 AM. Reason: Resolved
    Indecisiveness is the key to flexibility.

    www.mangojacks.com

  2. #2
    Frenzied Member stimbo's Avatar
    Join Date
    Jun 2006
    Location
    UK
    Posts
    1,739

    Re: Getting the screen area in VB.Net

    If you are using VS 2005 check out: My.Computer.Screen. .....

    it has access to methods like GetWorkingArea etc...

    It might be what you are looking for
    Stim

    Free VB.NET Book Chapter
    Visual Basic 2005 Cookbook Sample Chapter

  3. #3
    Frenzied Member dolot's Avatar
    Join Date
    Nov 2007
    Location
    Ancient City, U.S.
    Posts
    1,254

    Re: Getting the screen area in VB.Net

    check out the Windows.Forms.Screen class. I think you'll find it has the functionality you're looking for.
    I always add to the reputation of those whose posts are helpful, and even occasionally to those whose posts aren't helpful but who obviously put forth a valiant effort. That is, when the system will allow it.
    My war with a browser-redirect trojan

  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Getting the screen area in VB.Net

    Hey Ducan, long time no see.

    You can return the screen dimension in .NET with this
    Code:
    Dim intScrWidth As Integer = Screen.PrimaryScreen.Bounds.Width
    Dim intScrHeight As Integer = Screen.PrimaryScreen.Bounds.Height
    Does this help?

  5. #5

    Thread Starter
    Fanatic Member InvisibleDuncan's Avatar
    Join Date
    May 2001
    Location
    Eating jam.
    Posts
    819

    Re: Getting the screen area in VB.Net

    Hi, Hack! It certainly has been a while - I've been working on VB6 a lot lately, so I don't often need help...

    I don't have 2005 (we're a bit behind the times here!), but I'll certainly bear Stimbo's solution in mind for when we finally move on. As it was, Hack's post gave me exactly what I wanted.

    Thanks to all concerned - much appreciated.
    Indecisiveness is the key to flexibility.

    www.mangojacks.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width