Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / September 2004

Tip: Looking for answers? Try searching our database.

make controls on form centered when form maximized

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
TS - 21 Sep 2004 23:12 GMT
how do i do this first with one size monitor/ resolution, and hopefully with
any size monitor/screen resolution?

thanks
TS - 21 Sep 2004 23:21 GMT
I don't even know how to center it with my monitor/resolution becuase the
ide takes up space, so how do i know whats center besides counting pixels?

> how do i do this first with one size monitor/ resolution, and hopefully with
> any size monitor/screen resolution?
>
> thanks
"Jeffrey Tan[MSFT]" - 22 Sep 2004 02:21 GMT
Hi TS,

Based on my understanding, you want to centralize certain control on your
form.

Do you only want to centralize the control when maximizing? If the user
drag the border and change the form size, do you still want to centralize
the form?

Normally, we may calculate the form's width and height with control's width
and height, then we can get the correct control position:
this.button1.Left=(this.ClientSize.Width-this.button1.Width)/2;
this.button1.Top=(this.ClientSize.Height-this.button1.Height)/2;

We should place this code snippet in Form_Load event, so that when form
loading, the control is placed in the correct center position. Also, if you
want to keep control center position when user resize the form, we should
also place the form in Form.SizeChanged event:
private void Form1_SizeChanged(object sender, System.EventArgs e)
{
    this.button1.Left=(this.ClientSize.Width-this.button1.Width)/2;
    this.button1.Top=(this.ClientSize.Height-this.button1.Height)/2;
}

Another option: if you want the control's size changes with form resizing,
we may set this control's Anchor property to Top, Bottom, Left, Right. Then
after using the above code in Form.Load event, the control will reside in
the center and its will resize following form's resizing.(This solution may
meet your need, when you want to keep the control's scale with form)

These 2 options should both work under different solution.

===========================================
Please apply my suggestion above and let me know if it helps resolve your
problem.

Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Signature

Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

TS - 22 Sep 2004 16:42 GMT
thanks, that worked

> Hi TS,
>
[quoted text clipped - 41 lines]
> Get Secure! - www.microsoft.com/security
> This posting is provided "as is" with no warranties and confers no rights.
"Jeffrey Tan[MSFT]" - 23 Sep 2004 03:18 GMT
Hi TS,

You are welcome!! If you need further help, please feel free to tell me, I
am glad to work with you. Thanks

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Signature

Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.


Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.