XTab's Blog

Ged Mead's Blog at vbCity

This blog hosted by:
http://blogs.vbcity.com      
  Home :: Syndication  :: Login

AprMay 2008Jun
SMTWTFS
27282930123
45678910
11121314151617
18192021222324
25262728293031
1234567

Archives

Topics

Ramblings

VB.NET

  This tip barely qualifies as a Gotcha! but I have seen some people get stuck with it, so thought it worth a mention.

   If you want to control exactly where a second form is placed in relation to another form, you can use code that shifts the second form to either side or above or below the first one.  

  The key is to ensure that you set the StartPosition of the forms to "Manual".   If you do this, each form in the project that i set to Manual will automatically be placed at position 0,0 - i.e top left of the screen.  (By default this property is set to "WindowsDefaultLocation").

   So, to take a scenario with two forms, you can leave Form1 as-is and set the location of Form2 relative to Form1.

  For example to align the two forms horizontally but with Form2 placed immediately to the Right of Form1 you could use:

Code Copy

        Dim F2 As New Form2
        F2.Left = Me.Width + 2
        F2.Top = Me.Top
        F2.Show()

    As you can see the calculation is based on the width of the first form, plus a small margin added for appearance's sake.  The result  is:

 

  It's simple to use the same approach to place the second form anywhere you wish in relation to the first.  Below it, for example:

 

Code Copy
        Dim F2 As New Form2
        F2.Left = Me.Left
        F2.Top = Me.Height + 1
        F2.Show()

    So, just use whatever offset suits your needs, and don't forget to change that StartPosition property first.
posted on Sunday, August 05, 2007 12:15 PM

Feedback

No comments posted yet.

Post Feedback

Title:
Name:
Url:
Comments: 
Protected by Clearscreen.SharpHIPEnter the code you see: