Monday, December 12, 2005

Saving and restoring a forms location on

Raghavendra Prabhu has the start of some code to save/restore a form’s position.  This requires the Application Settings feature in 2.0, so this is mostly theoretical for me.

 private void Form1_FormClosing(object sender, FormClosingEventArgs e)
     Properties.Settings.Default.MyState = this

if (this.WindowState == FormWindowState.Normal)
   Properties.Settings.Default.MySize = this.Size;
   Properties.Settings.Default.MyLoc = this.Location;
   Properties.Settings.Default.MySize = this.RestoreBounds.Size;
   Properties.Settings.Default.MyLoc = this.RestoreBounds.Location;



private void Form1_Load(object sender, EventArgs e)

this.Size = Properties.Settings.Default.MySize;
this.Location = Properties.Settings.Default.MyLoc;
this.WindowState = Properties.Settings.Default.MyState;


As noted in the comments to his post, this code doesn’t take handle conditions like multiple instances running (each additonal app should offset it’s location) or if the resultion changed and the app is not off the screen.  But it’s a start.
via [jfo's coding]

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.