private void FormMain_Load(object sender, EventArgs e) { // Set window location if (Settings.Default.WindowLocation != null) { this.Location = Settings.Default.WindowLocation; } // Set window size if (Settings.Default.WindowSize != null) { this.Size = Settings.Default.WindowSize; } }步骤三:
private void FormMain_FormClosing(object sender, FormClosingEventArgs e) { // Copy window location to app settings Settings.Default.WindowLocation = this.Location; // Copy window size to app settings if (this.WindowState == FormWindowState.Normal) { Settings.Default.WindowSize = this.Size; } else { Settings.Default.WindowSize = this.RestoreBounds.Size; } // Save settings Settings.Default.Save(); }以上是原作者写的,窗体最小化后在任务栏右键关闭窗体,
再次打开窗体会有点问题,以下是不才写的
private void frmMain_FormClosing(object sender, FormClosingEventArgs e) { // Copy window location to app settings Settings.Default.WindowLocation = this.Location; // Copy window size to app settings if (this.WindowState == FormWindowState.Normal) { if (this.Size.Width != 0 && this.Size.Height != 0) { Settings.Default.WindowSize = this.Size; } } else { if (this.RestoreBounds.Size.Width != 0 && this.RestoreBounds.Size.Height != 0) { Settings.Default.WindowSize = this.RestoreBounds.Size; } } // Save settings if(this.WindowState!=FormWindowState.Minimized) Settings.Default.Save(); }