Results 1 to 7 of 7

Thread: [RESOLVED] About position and size

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Feb 2008
    Posts
    91

    Resolved [RESOLVED] About position and size

    hey guys, I'm using VB2008 and I was wondering this:
    I make my program start as "maximized" and place 1 button on the left upper corner and another button in the lower right corner, when I launch the program the buttons just places themself as in the design mode in VB, what can I do to make those buttons get in those corner? is it possible to put them in % ?
    This is because I want my program to work with every screen resolution, Thanks

    oh and by the way, I didn't know what this kind of problem where So therefor I couldn't search for it in the forums.

  2. #2
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,428

    Re: About position and size

    Possibly something along these lines:
    Code:
            Me.WindowState = FormWindowState.Maximized
            Me.Button1.Left = My.Computer.Screen.WorkingArea.Size.Width - Me.Button1.Width

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,302

    Re: About position and size

    You don't need any code at all. Simply position your Buttons where you want relative to the form edges, then set their Anchor properties to those edges. The Button in the top-left corner should have its Anchor set to (Top, Left), which is the default. The other should be set to (Bottom, Right), because you want the Button to remain in a fixed position relative to the bottom-right corner.

  4. #4
    New Member
    Join Date
    Jan 2010
    Posts
    3

    Re: About position and size

    Quote Originally Posted by Bruce Fox View Post
    Possibly something along these lines:
    Code:
            Me.WindowState = FormWindowState.Maximized
            Me.Button1.Left = My.Computer.Screen.WorkingArea.Size.Width - Me.Button1.Width
    Hi Bruce

    So to centre a form at runtime would one use something like the following?

    Me.Top= (My.Computer.Screen.WorkingArea.Size.Height - Me.Height) / 2
    Me.Left = (My.Computer.Screen.WorkingArea.Size.Width - Me.Width) / 2

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,302

    Re: About position and size

    Quote Originally Posted by ddclondon View Post
    Hi Bruce

    So to centre a form at runtime would one use something like the following?

    Me.Top= (My.Computer.Screen.WorkingArea.Size.Height - Me.Height) / 2
    Me.Left = (My.Computer.Screen.WorkingArea.Size.Width - Me.Width) / 2
    Assuming you mean when you open the form in the first place, to centre a form you would set its StartPosition property to CenterScreen.

  6. #6
    New Member
    Join Date
    Jan 2010
    Posts
    3

    Re: About position and size

    Quote Originally Posted by jmcilhinney View Post
    Assuming you mean when you open the form in the first place, to centre a form you would set its StartPosition property to CenterScreen.
    An elegant solution and you're a star!

    Thank you!

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Feb 2008
    Posts
    91

    Re: [RESOLVED] About position and size

    Thank you all for these lovely answers!

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