Reputation: 513
The Location
property in the form is set to 0,0 (Properties Window). However, the form doesn't open at the specified location. Am I missing something?
Upvotes: 32
Views: 62647
Reputation: 216243
Setting the Location at 0,0 has no effect if you forget to set StartPosition to FormStartPosition.Manual
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. You can also position the form to display in the center of the screen or in the center of its parent form for forms such as multiple-document interface (MDI) child forms.
Upvotes: 5
Reputation:
You need to set StartPosition
to manual to make the form set start position to the value in Location
Property.
public Form1()
{
InitializeComponent();
this.StartPosition = FormStartPosition.Manual;
this.Location = new Point(0, 0);
}
Intelisense Summary for FormStartPosition.Manual
FormStartPosition FormStartPosition.Manual
The position of the form is determined by the System.Windows.Forms.Control.Location property.
Upvotes: 67
Reputation: 550
By default the start position is set to be WindowsDefaultLocation which will cause the form to ignore the location you are setting. To easily have the set location enforced, change the StartPosition to Manual.
Upvotes: 6
Reputation: 223187
Try:
this.Location = new Point(Screen.PrimaryScreen.Bounds.X, //should be (0,0)
Screen.PrimaryScreen.Bounds.Y);
this.TopMost = true;
this.StartPosition = FormStartPosition.Manual;
Upvotes: 3