Is there a way to set the StartPosition of a Windows Forms form using code? It seems whatever I try results in the StartPostion being the default.
Here is what I am
public DealsForm()
{
InitializeComponent();
this.StartPosition = FormStartPosition.CenterParent;
}
Try to put it before InitializeComponent(). It might be already too late after InitializeComponent (the form might be already launch and the StatPosition is set too late).
I just wrote :
public Form1()
{
InitializeComponent();
this.StartPosition = FormStartPosition.CenterScreen;
}
And:
private void button1_Click(object sender, EventArgs e)
{
Form1 f = new Form1();
f.Show();
}
In a VS project (brand new) and when I click in my form2 a button it open the form in the middle of the screen. You can do the same with Parent...
Maybe you are not alone. Maybe you are not insane. Read this (Microsoft Connect Customer Feedback):
Windows Form StartPosition property only works for .ShowDialog method and not for .Show method
Customer: "Windows Form StartPosition only works for .ShowDialog method and not for .Show method. Note: I have also attached simple code and images of the results."
MS: "Unfortunately, we will not be able to fix this particular issue in a future release, as a fix here would be a breaking change to the behavior of WinForms 1, 1.1 and 2"