Joel in Gö
Joel in Gö

Reputation: 7580

Trying to make a dialog window remember its last position

I am creating a simple dialogue window in C#, and want to remember where it is placed so that I can open another in the same place later (during the same application run, so no need for config files etc). I can easily save the Location (a Point) or the Bounds (a Rectangle), but on creating another form, calling form.ShowDialog() resets both:

 Form form= new Form();   

 form.Location = ptSavedLocation;
 //now form.Location is correct

 form.ShowDialog();
 //now form.Location is default again, and form is displayed where I don't want it.

How can I get the form to respect its Location (or Bounds, or any other appropriate property / setter) ? Thanks!

Upvotes: 2

Views: 1660

Answers (2)

Geoff Appleford
Geoff Appleford

Reputation: 18832

Set the forms StartPosition property to Manual

Upvotes: 0

PaulB
PaulB

Reputation: 24392

Set the forms start position to Manual

eg.

 Form form= new Form();   

 form.StartPosition = FormStartPosition.Manual;

 form.Location = ptSavedLocation;
 //now form.Location is correct

 form.ShowDialog();
 //now form.Location is default again, and form is displayed where I don't want it.

Upvotes: 4

Related Questions