문제

I would like to save the user radio- button preference in the Settings file.

Therefore, I have created a setting property called radioButtonIsChecked boolean typed.

radioButton.Checked = Properties.Settings.Default[radioButton.Name + "IsChecked"];

When I try the code above I get an error that object cannot be converted to bool.
I understand the reason is that the returned value from Settings.Default indexer is object.

Is there a way to refer the settings- property type when retrieved from by-name-indexer?

도움이 되었습니까?

해결책

Assuming the retrieved value will be of the right type, just cast it:

radioButton.Checked = (bool) Properties.Settings.Default[radioButton.Name + "IsChecked"];
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top