Can anybody suggest why the label is not centering on the form using this code?Code:Private Sub Form_Load()
Me.WindowState = 2
With Label1
.Move (ScaleWidth - .Width) / 2, (ScaleHeight - .Height) / 2
End With
End Sub
Printable View
Can anybody suggest why the label is not centering on the form using this code?Code:Private Sub Form_Load()
Me.WindowState = 2
With Label1
.Move (ScaleWidth - .Width) / 2, (ScaleHeight - .Height) / 2
End With
End Sub
The form may not be resized yet. Try adding a DoEvents after setting the window state.
Tip: Add the label positioning to the form's Resize event vs the Load event. If you do, also check to ensure the WindowState<>vbMinimized before repositioning the label, because you will get an error positioning controls while form is minimized.