隐藏后保存窗体中的更改? [英] Save changes in windows form after hide ?

查看:70
本文介绍了隐藏后保存窗体中的更改?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


在我的Windows应用程序中我有两种形式

Mainform,子表格

在我的子表单中我有复选框

我的问题是在隐藏子窗体时保存我的复选框中的更改因为我读取了mainform中复选框的值



我尝试了什么:



我尝试将此代码添加到子窗体中的按钮

This.visible = false;

但是复选框恢复为默认值当重新打开子表单

Hi In my windows application i have two forms
Mainform , subform
In my subform i have checkbox
My problem is to save change in my checkbox when hide subform becouse i read value for checkbox in mainform

What I have tried:

I try to add this code to button in subform
This.visible=false;
But checkbox back to default when reopen subform

推荐答案

更改任何状态不是永久性的,除非你专门编写它。



处理此问题的最佳方法是添加设置:

1)在解决方案资源管理器中打开项目属性,然后双击Settings.settings

2)在结果网格中,将Name更改为MySetting,并将Value设置为Defaultaulted value。将类型和范围分别保留为字符串和用户。

3)保存并关闭设置窗口。

4)阅读设置:

Changing the state of anything isn't permanent unless you specifically code for it to be.

The best way to handle this would be to add a setting:
1) Open your projects Properties in the solution explorer, and double click on "Settings.settings"
2) In the resulting grid, change the Name to "MySetting", and set the Value to "Defaulted value". Leave Type and Scope as "string" and "User" respectively.
3) Save and close the settings window.
4) To read your setting:
string s = Properties.Settings.Default.MySetting;

5)写下你的设置:

5) To write your setting:

Properties.Settings.Default.MySetting = "My new setting value";
Properties.Settings.Default.Save();

然后将代码添加到表单保存和加载方法以使用保存的设置,并在表单加载和关闭事件中更新复选框的可见状态。

Then add code to the form save and load methods to use the saved setting and update the visible status of your checkbox in the form Load and Close events.


这篇关于隐藏后保存窗体中的更改?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆