Page 1 of 1

forms

Posted: Fri May 14, 2010 10:27 pm
by Mark
hello,

can anyone tell me how to open two forms at once when you start the program but one has to be on the left of the main form can anyone help me please?

Re: forms

Posted: Fri May 14, 2010 11:06 pm
by mandai
To add a new form to a project you right click the solution explorer then choose to add, then new windows form.
Once you have added it you can make it appear with Form.Show() and Form.ShowDialog().

If you want it to appear to the left of an existing form then before you show it you could set the StartPosition to Manual and use code like this:
Code: Select all
newForm.Location = new Point(Me.Location.X - newForm.Width, Me.Location.Y)

Re: forms

Posted: Fri May 14, 2010 11:27 pm
by Mark
mandai wrote:
To add a new form to a project you right click the solution explorer then choose to add, then new windows form.
Once you have added it you can make it appear with Form.Show() and Form.ShowDialog().

If you want it to appear to the left of an existing form then before you show it you could set the StartPosition to Manual and use code like this:
Code: Select all
newForm.Location = new Point(Me.Location.X - newForm.Width, Me.Location.Y)
I tried this code
Code: Select all
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Form2.Location = New Point(Me.Location.X - Form2.Width, Me.Location.Y)
        Form2.ShowDialog()
    End Sub
But it still dosent work it shows form 2 and not form1?

Re: forms

Posted: Sat May 15, 2010 2:08 am
by CodenStuff
Hello,

Put the code into the "Form_Shown" event instead of "Form_Load":
Code: Select all
Private Sub Form1_Shown(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Shown
        Dim SecondForm As New Form2
        SecondForm.Location = New Point(Me.Bounds.Left - SecondForm.Width, Me.Location.Y)
        SecondForm.ShowDialog()
    End Sub

Re: forms

Posted: Sat May 15, 2010 7:33 pm
by mandai
If you have it show the form in the load event and you want it on the left, you need to change Form2.StartPosition to FormStartPosition.Manual.