Parent Form
-
here's what I'm sure is an easy one... I have a project with 5 different windows forms. One is the main program form and 4 of them are displayed by clicking a button on the main form. I'm trying to get each form centered on the main form (they are all modal dialogs). I've chosen "center on parent" on the property sheet for each form, but each form is still spawning what seems to be randomly on screen. I don't think that the main form of the project is set as the parent form for each of the other forms. Is this what the problem is and if so how can I go about giving each form a child relationship to the main form? Thanks, John BTW I'm using Visual Studio 2005 Standard Edition. -- modified at 21:06 Friday 9th December, 2005
-
here's what I'm sure is an easy one... I have a project with 5 different windows forms. One is the main program form and 4 of them are displayed by clicking a button on the main form. I'm trying to get each form centered on the main form (they are all modal dialogs). I've chosen "center on parent" on the property sheet for each form, but each form is still spawning what seems to be randomly on screen. I don't think that the main form of the project is set as the parent form for each of the other forms. Is this what the problem is and if so how can I go about giving each form a child relationship to the main form? Thanks, John BTW I'm using Visual Studio 2005 Standard Edition. -- modified at 21:06 Friday 9th December, 2005
You are correct. For them to properly center they must have the parent form set. To do this just pass in the parent form as the first paramater to the ShowDialog() method. For instance
public void OnButtonClick(object sender, EventArgs e) { SomeForm child = new SomeForm(); if ( DialogResult.OK == child.ShowDialog(this) ) { ... } }
Jared Parsons jaredp@beanseed.org http://spaces.msn.com/members/jaredp/ -
You are correct. For them to properly center they must have the parent form set. To do this just pass in the parent form as the first paramater to the ShowDialog() method. For instance
public void OnButtonClick(object sender, EventArgs e) { SomeForm child = new SomeForm(); if ( DialogResult.OK == child.ShowDialog(this) ) { ... } }
Jared Parsons jaredp@beanseed.org http://spaces.msn.com/members/jaredp/Thanks a bunch Jared, got it working :) Thanks, John