Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB VB.NET
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 25-Nov-12 22:53pm
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 307
1 Nirav Prabtani 268
2 Sergey Alexandrovich Kryukov 182
3 _Amy 170
4 Mika Wendelius 165
0 Nirav Prabtani 284
1 OriginalGriff 207
2 _Amy 170
3 Mika Wendelius 165
4 Sergey Alexandrovich Kryukov 119


Advertise | Privacy | Mobile
Web04 | 2.8.140721.1 | Last Updated 26 Nov 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100