9 Replies - 5135 Views - Last Post: 16 November 2010 - 02:59 PM Rate Topic: -----

#1 mjw85  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 52
  • Joined: 01-October 07

Adjust Form based on Screen resolution

Posted 16 November 2010 - 09:47 AM

I am currently trying to re-size my Visual Basic forms based on the screen resolution - to fit no matter what the user's screen resolution is set to. So far I have tried:

Rectangle r = Screen.GetBounds(this);
this.Location = new Point(0, 0);
 this.Size = r.Size;



which does nothing, but seems to be the only reference I can find out there. Is this even possible? Any suggestions/help are appreciated. Thanks!

Is This A Good Question/Topic? 0
  • +

Replies To: Adjust Form based on Screen resolution

#2 elbielefeld  Icon User is offline

  • D.I.C Head

Reputation: 70
  • View blog
  • Posts: 216
  • Joined: 18-May 10

Re: Adjust Form based on Screen resolution

Posted 16 November 2010 - 10:24 AM

Try it with this:

this.WindowState = FormWindowState.Maximized;

Was This Post Helpful? 0
  • +
  • -

#3 mjw85  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 52
  • Joined: 01-October 07

Re: Adjust Form based on Screen resolution

Posted 16 November 2010 - 10:29 AM

Thanks for your reply - Already tried with no luck. :(
Was This Post Helpful? 0
  • +
  • -

#4 biggerB  Icon User is offline

  • If at first you don’t succeed, call it version 1.0
  • member icon

Reputation: 80
  • View blog
  • Posts: 760
  • Joined: 11-June 10

Re: Adjust Form based on Screen resolution

Posted 16 November 2010 - 10:40 AM

Try this

Rectangle r = Screen.GetWorkingArea(Form1.PointToScreen);
this.Location = new Point(0, 0);
 this.Size = r.Size;

Was This Post Helpful? 0
  • +
  • -

#5 elbielefeld  Icon User is offline

  • D.I.C Head

Reputation: 70
  • View blog
  • Posts: 216
  • Joined: 18-May 10

Re: Adjust Form based on Screen resolution

Posted 16 November 2010 - 10:40 AM

What means no luck? Do you really mean "Visual Basic forms" or Windows Forms?
Was This Post Helpful? 0
  • +
  • -

#6 mjw85  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 52
  • Joined: 01-October 07

Re: Adjust Form based on Screen resolution

Posted 16 November 2010 - 10:43 AM

View Postelbielefeld, on 16 November 2010 - 09:40 AM, said:

What means no luck? Do you really mean "Visual Basic forms" or Windows Forms?

No luck means that it didn't work - using Windows forms within Visual Studio

This post has been edited by mjw85: 16 November 2010 - 10:51 AM

Was This Post Helpful? 0
  • +
  • -

#7 eclipsed4utoo  Icon User is offline

  • Not Your Ordinary Programmer
  • member icon

Reputation: 1524
  • View blog
  • Posts: 5,957
  • Joined: 21-March 08

Re: Adjust Form based on Screen resolution

Posted 16 November 2010 - 10:50 AM

View Postmjw85, on 16 November 2010 - 01:43 PM, said:

View Postelbielefeld, on 16 November 2010 - 09:40 AM, said:

What means no luck? Do you really mean "Visual Basic forms" or Windows Forms?

No luck means that it didn't work - using Windows forms within Visual Basic


It's Visual Studio, not Visual Basic. Visual Studio is the IDE where you do your development. Visual Basic is a programming language....maybe you have heard of it...it's commonly referred to as VB.Net.
Was This Post Helpful? 0
  • +
  • -

#8 elbielefeld  Icon User is offline

  • D.I.C Head

Reputation: 70
  • View blog
  • Posts: 216
  • Joined: 18-May 10

Re: Adjust Form based on Screen resolution

Posted 16 November 2010 - 10:55 AM

If "it didn't work" means the window is not maximized, there is probably something wrong with your code. Can you post it?
Was This Post Helpful? 0
  • +
  • -

#9 Robin19  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 256
  • View blog
  • Posts: 529
  • Joined: 07-July 10

Re: Adjust Form based on Screen resolution

Posted 16 November 2010 - 02:48 PM

I think the poster means that everything on the form should fit on the screen, no matter the resolution. If I have 30 controls on a form and I can see them all on 1280x1024, I should still be able to see all 30 controls if the resolution is set to 600x800.

I have this happening in my current project. We do not know what computer the project will run on. It could be a small screen or a touch screen or a huge monitor. I manually resize every control using percentages.
            // section one
            this.Width = Screen.PrimaryScreen.Bounds.Width;
            this.Height = Screen.PrimaryScreen.Bounds.Height;
            // section two
            this.Width = Screen.PrimaryScreen.WorkingArea.Width;
            this.Height = Screen.PrimaryScreen.WorkingArea.Height;
            // location
            this.Location = new Point(0, 0);

Section one will cause the screen to fill the whole screen. Section two will fill the working area (ie it will not overlap the start menu). Then I set each button's Width, Height, and Location as a percentage based on the form's Width and Height. It is not easy, nor is it pretty, but it works.
Was This Post Helpful? 1
  • +
  • -

#10 Curtis Rutland  Icon User is online

  • (╯°□°)╯︵ (~ .o.)~
  • member icon


Reputation: 4309
  • View blog
  • Posts: 7,455
  • Joined: 08-June 10

Re: Adjust Form based on Screen resolution

Posted 16 November 2010 - 02:59 PM

Robin, that's one of the reasons I love silverlight/wpf is that by default, controls scale to fill their surrounding containers. So by setting margins, paddings, and alignments, you can create a form that is either static or stretchable, and all the controls stretch with it.

But from what I can tell, I don't think this is a question of scaling or layout. I think he's trying to resize the window to fit screen resolution. And my guess is that if the code provided didn't work, that code might not even be getting executed.

mjw85, please put a breakpoint on the line that you've inserted the provided code, and see if execution stops at that point. If it does, then you know at least that code is being executed.

Also, please remember to be detailed in your replies. We're not mind readers, and we're not personally invested in your project. We're just here because we like to help. But if you make that difficult, then we just move on to the next thread.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1