My problem is that my form is not in the middle of the screen even though StartPosition is set to CenterScreen. Does anyone know why or how to fix us?
Printable View
My problem is that my form is not in the middle of the screen even though StartPosition is set to CenterScreen. Does anyone know why or how to fix us?
CenterScreen works for me in all applications I ever developed. Maybe you set not to CenterScreen but to CenterParent? That does not work. More I can not say without knowing your code.
Definately CenterScreen, was working then somewhere along the line. I have also tryed:
[code]this.Location = new Point(((Screen.GetBounds(this).Width - this.Width)/2), ((Screen.GetBounds(this).Height - this.Height)/2));
I suppose you're setting the property before you display the form, right?
It's okay I fixed it with this:
Code:this.StartPosition = System.Windows.Forms.FormStartPosition.Manual;
this.Location = new System.Drawing.Point(
((System.Windows.Forms.Screen.GetBounds(this).Width - this.ClientSize.Width) / 2),
((System.Windows.Forms.Screen.GetBounds(this).Height - this.ClientSize.Height) / 2)
);
I have same problem... C# application with some wizard based forms... in properties I set start position to CenterScreen but it opens in upper left corner... not completely at 0,0 but in upper left.
I tried the suggestion of adding the code to the function InitForm...no change.
I looked at InitComponent and there is a line of code there also setting start position to Center Screen.
ANy other suggestions?
Pass the parent window to the child form before displaying.
How?
Using VS 2008
Create a static method in the child form.
Code:public static DialogResult ShowDlg( Form parent )
{
var dlg = new Form2( ) { Owner = parent };
return dlg.ShowDialog( );
}
In the Form2 properties, set the StartPosition property to CenterParent.
In a button handler of Form1, call the static ShowDlg method and pass in the 'this' member.
Code:private void button1_Click( object sender, EventArgs e )
{
if( DialogResult.OK == Form2.ShowDlg( this ) )
{
// do something here when the OK button has been clicked
}
}