jp2*_*ode 24 c# visual-studio-2010 winforms
我似乎无法阻止我从形式检查的一个单选按钮在我的Group Box
:
如设计器所示,那里没有检查Radio Buttons.
下面是这个简单表单的所有代码.没有什么要求在这里或在表单的设计者中检查单选按钮.
问:有没有办法防止在表单加载时检查任何单选按钮?
public ValueTypeSelector() {
InitializeComponent();
radioButton1.Checked = false;
radioButton2.Checked = false;
radioButton3.Checked = false;
radioButton4.Checked = false;
radioButton5.Checked = false;
radioButton6.Checked = false;
button1.Enabled = false;
button1.Click += clickEvent;
button2.Click += clickEvent;
radioButton1.Click += clickEvent;
radioButton2.Click += clickEvent;
radioButton3.Click += clickEvent;
radioButton4.Click += clickEvent;
radioButton5.Click += clickEvent;
radioButton6.Click += clickEvent;
}
void OnShow(object sender, EventArgs e) {
foreach (RadioButton rad in Controls) {
if (rad.Checked) {
Console.WriteLine("WTF?");
}
}
}
void clickEvent(object sender, EventArgs e) {
RadioButton rad = sender as RadioButton;
if (rad != null) {
if (rad.Checked) {
if (rad == radioButton1) {
DataType = TableDataType.Boolean; // <= HERE IS THE PROBLEM! FIRES ON FORM LOAD
} else if (rad == radioButton2) {
DataType = TableDataType.Character;
} else if (rad == radioButton3) {
DataType = TableDataType.DateTime;
} else if (rad == radioButton4) {
DataType = TableDataType.Decimal;
} else if (rad == radioButton5) {
DataType = TableDataType.Integer;
} else if (rad == radioButton6) {
DataType = TableDataType.String;
} else {
return;
}
button1.Enabled = true;
}
} else if (sender == button1) {
DialogResult = DialogResult.OK;
Close();
} else if (sender == button2) {
DialogResult = DialogResult.Cancel;
Close();
}
}
Run Code Online (Sandbox Code Playgroud)
更新:问题是radioButton1
在显示表单时检查:
if (rad == radioButton1) {
DataType = TableDataType.Boolean; // <= HERE IS THE PROBLEM! FIRES ON FORM LOAD
} else if (rad == radioButton2) {
Run Code Online (Sandbox Code Playgroud)
Lar*_*ech 28
确保您的radiobuttons不是第一个tabindex = 0控件.按OK按钮tabindex = 0,然后是radiobuttons.
Sar*_*gam 14
在设计模式下,您会发现AutoCheck属性设置为true.只需将其变为假.在运行期间手动选择它时,不会检查它.
归档时间: |
|
查看次数: |
27696 次 |
最近记录: |