C# - 紀錄使用者視窗大小與位置、應用程式預設值

  • 57112
  • 0
  • C#
  • 2008-03-22

C# - 紀錄使用者視窗大小與位置、應用程式預設值

(1) 屬性視窗 -> (ApplicationSettingS) -> (PropertyBinding) 點擊圖示

(2) 將視窗拉到 TopMost 點擊 【(無)】下拉選單 -> 新增
DeaultVaue:True、名稱:TopMost、Scope:Applicaiton

(3) 方案總管 -> Properties -> Settings.settings 按右鍵,選擇【開啟】

(4) 新增屬性 Size 與 Location

名稱 型別 範圍
Size System.Drawing.Size User 300,300
Location System.Drawing.Point User 0,0
TopMost bool User true

(5) 處理視窗 Load 事件與 FormClosing 事件

            
  1. private void Form1_Load( object sender, EventArgs e)
  2. {
  3. Settings ps = Settings.Default;
  4. this.Size = ps.Size;
  5. this.Location = ps.Location;
  6. }
  7.  
  8. private void Form1_FormClosing( object sender, FormClosingEventArgs e)
  9. {
  10. Settings ps = Settings.Default;
  11. ps.Size = this.Size;
  12. ps.Location = this.Location;
  13. ps.Save ( );
  14. }
  15.