StartPosition=CenterParent doesn't work half the time
-
The form I am dealing with pops up in the middle of the application only half time time. The other half the time it goes into the upper-left corner. If I set a break point inside the form to check what the parent is - it's always null. But it's null for all the forms in our app, yet this is the only form that is acting funky. I was wondering if anyone else ran into problems with setting StartPosition to CenterParent. Thanks, Elena
-
The form I am dealing with pops up in the middle of the application only half time time. The other half the time it goes into the upper-left corner. If I set a break point inside the form to check what the parent is - it's always null. But it's null for all the forms in our app, yet this is the only form that is acting funky. I was wondering if anyone else ran into problems with setting StartPosition to CenterParent. Thanks, Elena
I have seen this. However I have not taken the time to determine what I'm doing when it works and what I'm doing when it does not work. (ie. form.Show() vs. form.ShowDialog()) This signature left intentionally blank
-
The form I am dealing with pops up in the middle of the application only half time time. The other half the time it goes into the upper-left corner. If I set a break point inside the form to check what the parent is - it's always null. But it's null for all the forms in our app, yet this is the only form that is acting funky. I was wondering if anyone else ran into problems with setting StartPosition to CenterParent. Thanks, Elena
elena12345 wrote: I was wondering if anyone else ran into problems with setting StartPosition to CenterParent You need to make sure your child form instance sets the it's
Parent
property before you display your form, that is assuming you are setting youStartPosition
toCenterParent
. If you don't have a parent, just set theStartPosition
toCenterScreen
to get the form centered on the screen. - Nick Parker
My Blog | My Articles -
elena12345 wrote: I was wondering if anyone else ran into problems with setting StartPosition to CenterParent You need to make sure your child form instance sets the it's
Parent
property before you display your form, that is assuming you are setting youStartPosition
toCenterParent
. If you don't have a parent, just set theStartPosition
toCenterScreen
to get the form centered on the screen. - Nick Parker
My Blog | My ArticlesExactly. If you set the CenterParent property before the parent is known, it will have no effect. For instance If you set the CenterParent in the designer, it will be set when the constructor calls the designer generated code, at which point the parent is still unknown. The way to go here is either: Create a constructor that takes the parent form as a parameter, and then set the Parent property before calling the designer generated code Or: When you create the child form in the parent form, first set the Parent Property, then the StartPosition property and then call the Show(Dialog) method.