Click here to Skip to main content
15,886,680 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Dear Coders,

I know that we can make the window to appear in the center of the screen by changing startposition from the form properties. But i would like to know once the window is maximized how do we make things to be contained in the center of the form? Please Help.
Posted

In the form designer, on the controls you want to keep at the same relative position to the center of the form, just set Anchor to None.
In a form, with all its controls with Anchor=None, when the form is resized, it will appear as the form is extended on every side (up, down, left, right) with all the initial controls at the same position at the center of the form.
 
Share this answer
 
You take the width and height of the mainform and the width and height of the object you want to centralise and subtract one from the other and divide by two.

Sub Centralise(CenterThis as object, InThisForm as object)
  CenterThis.left = (InThisForm.Width - CenterThis.Width) / 2
  CenterThis.top = (InThisForm.Height - CenterThis.Height) / 2
End Sub
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900