Hii,
I have created a form.I open the form on the click event of a button.I want to open the form in the centre of the form on which the button is placed.Ne suggestions how to do it.
Following is wat i have implemented.
public
partial class FormSelectParameters : Form{
........etc
}
In other application i have a button on whose click event i reate a new instance of above form.Her is the code.
private void btnSelectParameters_Click(object sender, EventArgs e){
Form frmselParam = new FormSelectParameters();
if (frmselParam.ShowDialog(this) == DialogResult.OK){
frmselParam.Visible =
false;//Tried the below line.Gives an exception saying Top level controls cannot be added.
frmselParam.Parent=this;
}
I want to open the form at the centre of the form which is having
btnSelectParameters.
Swetha BPosted Feb 19, 2009, 4:25 AM
public void setWindowLocation(int windowLeft, int windowTop) { this.StartPosition=FormStartPosition.Manual; Point windowlocation = new Point(); windowlocation.X = (windowleft) - (this.Width / 2); windowlocation.Y = (windowtop) - (this.Height / 2); this.Location = windowlocation; }And use the above method as below Set the location of your form when you are opening the formint window_left = parentform.Left + (parentform.Width / 2); int window_top = parentform.Top + (parentform.Height / 2); Window.setWindowLocation(window_left, windowr_top);Hope this will be helpful for you.Jan MontanoPosted Feb 9, 2009, 8:06 PM
private void btnSelectParameters_Click(object sender, EventArgs e)
{
Form frmselParam = new FormSelectParameters();
frmselParam.StartPosition = FormStartPosition.CenterParent;
if (frmselParam.ShowDialog(this) == DialogResult.OK)
{
}