Form positioning

I have a form with a datagrid on it, I would like to open another form and position the upper left corner in the same spot of the datagrids upper left corner.

Thanks
mrf1001Asked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
rspahitzConnect With a Mentor Commented:
' code somewhere in form1
Load Form2
'...
Form2.Show

' code in Form2
Private Sub Form_Load()
  Me.Move Form1.Left + (Form1.Width - Form1.ScaleWidth) / 2 + Form1.txtEntireText.Left, Form1.Top + (Form1.Height - Form1.ScaleHeight - (Form1.Width - Form1.ScaleWidth) / 2) + Form1.txtEntireText.Top
End Sub
0
 
rspahitzCommented:
Basically, move the new form to the location of the previous form, then shift it over to the right of the form's border (*) then shift it the distance of the desired control (in your case the datagrid.)

Do the same with the top, except that the height of the top form border is the form's height minus the scaleheight minus the bottom border.  But the bottom border cannot be captured directly so you have to take 1/2 of the side border (which was also calculated for the width.)

(*) Form's border= 1/2 the difference between the form's width and the form's workarea width (aka scalewidth)
0
 
kavithagCommented:
Create the II FORM dynamically through code and place the db grid and on it and position it as the first form
0
 
mrf1001Author Commented:
Works great with some minor modification

Thanks
0
 
rspahitzCommented:
Great!  Glad to help.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.