Save and Restore Form Position and Size

前端 未结 8 2185
说谎
说谎 2020-12-14 04:36

In a WinForms 2.0 C# application, what is the typical method used for saving and restoring form position and size in an application?

Related, is it possible to add n

8条回答
  •  半阙折子戏
    2020-12-14 05:24

    You could create a base form class with common functionality such as remembering the position and size and inherit from that base class.

    public class myForm : Form {
    protected override void OnLoad(){
        //load the settings and apply them
        base.OnLoad();
    }
    
    protected override void OnClose(){
        //save the settings
        base.OnClose();
    }
    }
    then for the other forms:
    
    public class frmMainScreen : myForm {
    // you get the settings for free ;)
    }

    Well, something like that ;)

提交回复
热议问题