[RESOLVED] center a smaller form over the calling form
i am trying to center a smaller form over the calling form
like this:
code in the smaller form
Public Sub CenterMe(frm As Form)
Me.Left = frm.ScaleWidth / 2 - Me.Width / 2
Me.Top = frm.ScaleHeight / 2 - Me.Height / 2
Me.Show
End Sub
Calling it like this:
form1.CenterMe frmKeno
The smaller form is too far left and not high enough. (not centered)
what am i doing wrong ?
Re: center a smaller form over the calling form
1. You are not taking into account the main form's Left & Top properties
2. Not sure why you're using width for one form and scalewidth for the other, etc.
Code:
Private Sub CenterMe(Main As Form)
Left = Main.Left + (Abs(Main.ScaleWidth - ScaleWidth)) \ 2
Top = Main.Top + (Abs(Main.ScaleHeight - ScaleHeight)) \ 2
End Sub
Re: center a smaller form over the calling form
thanks that fixed the issue
Not sure why you're using width for one form and scalewidth for the other, etc.
i was trying different things
Re: [RESOLVED] center a smaller form over the calling form
It can also be done by setting the StartUpPosition property to "1 - CenterOwner" on the form you are trying to center and then from the other form call it using the syntax
Form2.Show , Me
No calculations required.
Re: [RESOLVED] center a smaller form over the calling form