C# Setting步骤一:打开项目属性窗口,切换到设置(Settings)标签,
网站建设哪家好,找成都创新互联!专注于网页设计、网站建设、微信开发、微信小程序、集团企业网站建设等服务项目。为回馈新老客户创新互联还提供了宁陕免费建站欢迎大家使用!
如下图添加属性
Name Type Scope Value
WindowLocation System.Drawing.Point User 0,0
WindowSize System.Drawing.Size User 300,300
C# Setting步骤二:
在要保存状态的窗体代码头部添加代码
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;
- }
- }
C# Setting步骤三:
在窗体的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 != 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();
- }
分享标题:C#Setting保存窗体
分享URL:http://www.mswzjz.cn/qtweb/news6/401006.html
攀枝花网站建设、攀枝花网站运维推广公司-贝锐智能,是专注品牌与效果的网络营销公司;服务项目有等
声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 贝锐智能