Click here to Skip to main content
11,577,388 members (57,554 online)
Rate this: bad
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
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.
Rate this: bad
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 = (InThisForm.Height - CenterThis.Height) / 2
End Sub

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

  Print Answers RSS
0 DamithSL 180
1 Afzaal Ahmad Zeeshan 125
2 OriginalGriff 115
3 Richard MacCutchan 100
4 Abhinav S 90
0 OriginalGriff 820
1 Sergey Alexandrovich Kryukov 681
2 Abhinav S 528
3 F-ES Sitecore 420
4 Suvendu Shekhar Giri 375

Advertise | Privacy | Mobile
Web04 | 2.8.150603.1 | Last Updated 26 Nov 2012
Copyright © CodeProject, 1999-2015
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