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
Get Secure! -
www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.