您现在的位置是:首页 >

java 自定义窗体缩放 C#中使用Setting保存用户自定义窗体位置

火烧 2021-12-18 16:48:45 1059
C#中使用Setti g保存用户自定义窗体位置 方法 步骤一 打开项目属性窗口 切换到设置 Setti g 标签 如下图添加属性 Name Ty e Sco e Value Wi dowLocatio
java 自定义窗体缩放 C#中使用Setting保存用户自定义窗体位置

C#中使用Setting保存用户自定义窗体位置  

方法   步骤一 打开项目属性窗口 切换到设置(Settings)标签   如下图添加属性 Name Type Scope Value WindowLocation System Drawing Point User WindowSize System Drawing Size User   步骤二   在要保存状态的窗体代码头部添加   using UserSettingsDemo Properties;   在窗体的FormLoad事件中添加以下代码

   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; } }

  步骤三   在窗体的FormClosing事件中添加如下代码

   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 != && this Size Height != ) { Settings Default WindowSize = this Size; } } else { if (this RestoreBounds Size Width != && this RestoreBounds Size Height != ) { Settings Default WindowSize = this RestoreBounds Size; } } // Save settings if(this WindowState!=FormWindowState Minimized) Settings Default Save(); }

lishixinzhi/Article/program/net/201311/12617  
永远跟党走
  • 如果你觉得本站很棒,可以通过扫码支付打赏哦!

    • 微信收款码
    • 支付宝收款码