how to set form startup location/position manually?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am instnatiating a second form from a first form. I set startuplocation to
manual, then I enter 100 for X and 300 for Y on the second form. Then on the
click event of a button on form1 I have Dim frm = New form2, frm.Show. But
form2 shows up way to the right of the screen. I also tried this in code

frm.Location = New Point(100, 300)

but same results. How do you control the position of a form in VB.Net?

Thanks,
Rich
 
Rich said:
I am instnatiating a second form from a first form. I set startuplocation
to
manual, then I enter 100 for X and 300 for Y on the second form. Then on
the
click event of a button on form1 I have Dim frm = New form2, frm.Show.
But
form2 shows up way to the right of the screen.

Make sure the form's 'StartPosition' property is set to 'Manual'.
 
Rich said:
I am instnatiating a second form from a first form. I set startuplocation to
manual, then I enter 100 for X and 300 for Y on the second form. Then on the
click event of a button on form1 I have Dim frm = New form2, frm.Show. But
form2 shows up way to the right of the screen. I also tried this in code

frm.Location = New Point(100, 300)

but same results. How do you control the position of a form in VB.Net?

Thanks,
Rich

Here is an example which might help...The child form is positioned in
relations to a CheckBox on the calling form. So no matter were the user moves
the form it is always were it should be in relation to the caller.

Dim f As New frmYourForm
Try
With f
.RunCode = True
.Location = Me.PointToScreen(New Point(CheckBox1.Left, CheckBox1.
Top + CheckBox1.Height))
.ShowDialog(Me)
End With
Finally
f.Dispose()
End Try
 
Thank you all for your replies. I am setting StartPosition to Manual, and I
have tried the suggestions, but my form is still not behaving as desired. I
don't know if the following makes a difference, but the second form is
actually an indipendent form - not a child form (of an mdi form). One thing
I just noticed is this - if I set the startposition to CenterScreen or
CenterParent - the second form is not behaving as expected. The property is
being ignored. I only have 2 forms, so it is not like I am picking the wrong
form. If I set the primary form to CenterScreen - it appears on CenterScreen
as expected, but the second form does not behave as expected. Is there a
property I need to set/unset perhaps?

Thanks,
Rich
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top