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 doing in the form to display:
public DealsForm()
{
InitializeComponent();
this.StartPosition = FormStartPosition.CenterParent;
}
Here is what I am doing to display the form:
private void nvShowDeals_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
DealsForm frm = new DealsForm();
frm.DataSource = this.Deals;
frm.Show(this);
}
I have tried putting the following in each of the above methods, to no avail:
this.StartPosition = FormStartPosition.CenterParent;
If I set it via the Property Editor ... it works perfectly, but I would really like to do it via code.
Should be a no-brainer ... but for the life of me I can't seem to figure it out ... maybe I need more caffeine.
If I do a ShowDialog()
and pass the parent it works ... but I really don't want to show it as a Dialog.
Select the form, then find the Properties pane in Visual Studio. Scroll down to size and expand it. You can set the Width and Height manually.
Remarks. This enumeration is used by the StartPosition property of the Form class. It represents the different start positions of the form. The default start position is WindowsDefaultLocation .
This property enables you to set the starting position of the form when it is displayed at run time. The form's position can be specified manually by setting the Location property or use the default location specified by Windows.
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"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With