使用的applicationSettings来存储的WinForms单选按钮选中属性单选、按钮、属性、applicationSettings

2023-09-03 01:07:23 作者:回忆是糖゛甜到忧伤づ

我有一个包含3单选按钮的WinForms对话框。我使用的applicationSettings 来每种单选控制检验属性绑定,但它没有做什么,我我希望做的事。现在,我必须单击每个单选按钮前两次它被检查,并没有被持久化的单选按钮。

I have a WinForms dialog box that contains 3 radio buttons. I am using ApplicationSettings to bind the Checked property of each of these RadioButton controls, but it doesn't do what I am expecting it to do. Now I have to click each radio button twice before it gets checked and the selected radio button is not being persisted.

有一行code,我需要在窗体关闭,节省了用户设置?执行

Is there a line of code I need to execute when the form is closed that saves the user settings?

如何省去了2倍上点击单选按钮?

How do I eliminate the need for 2x clicking on the radio buttons?

有没有更好的方式来坚持这种类型的用户设置?我有上获取对话框类中的公共属性/设置一个枚举值,在此基础上单选按钮被选中,但我没有看到那个属性绑定到用户设置一个简单的方法。

Is there a better way to persist this type of user setting? I do have a public property on the dialog box class that gets/sets an enum value based on which radio button is checked, but I didn't see an easy way of binding that property to a user setting.

编辑:如果已指定我使用vb.net。我认为, My.Settings 来代替 Properties.Settings

Should have specified that I'm using vb.net. I think that means My.Settings instead of Properties.Settings.

推荐答案

我可以回答你这部分的问题:

I can answer this part of your question:

有一行code,我需要在窗体关闭,节省了用户设置?执行

Is there a line of code I need to execute when the form is closed that saves the user settings?

应用程序设置存储在你的设置类,在属性命名空间。该设置类有一个静态属性称为默认,从而重新presents当前应用程序的设置。因此,在你的主窗体的Closing事件,你可以调用:

Application settings are stored in your Settings class, in the Properties namespace. The Settings class has a static property called Default, which represents the current settings for your application. So in your main form's Closing event, you call:

Properties.Settings.Default.Save();

...保存设置。

... to save the settings.

同样,你也可以去设置使用编程设定的名称: Properties.Settings.Default.MyRadioButtonState (或任何你叫吧)

Likewise you can get to the settings programatically using the setting's name: Properties.Settings.Default.MyRadioButtonState (or whatever you've called it).