【发布时间】:2018-08-30 04:33:10
【问题描述】:
我正在用 C# 编写一个软件,我在其中使用 regedit 来存储用户的一些偏好。其中一项偏好是:选中哪个单选按钮。看起来是这样的:
String readPreference = (String)Registry.GetValue(RegLocation, "Preference", "true;false");
var temp = readPreference.Split(new string[] { ";" }, StringSplitOptions.None);
radioButton1.Checked = bool.TryParse(temp[0], out tempBool);
radioButton2.Checked = bool.TryParse(temp[1], out tempBool);
但无论 temp[0] 和 temp[1] 的值如何,RadioButton1.Checked 将始终为 false,RadioButton2.Checked 将始终为 true。
这里有两种可能的情况,第一种:
temp[0] = false;
temps[1] = true;
radioButton1.Checked = temp[0] //it's supposed to become false but it stays true
radioButton2.Checked = temp[1] //it becomes true
所以radioButton1.Checked 变为假,radioButton2.Checked 保持为真。
第二个:
temp[0] = true;
temps[1] = false;
radioButton1.Checked = temp[0] //it becomes true
radioButton2.Checked = temp[1] //it becomes false
但随后,radioButton1.Checked 变为假,radioButton2.Checked 变为真
这怎么可能?如何解决?
【问题讨论】:
标签: c# .net radio-button