我怎样才能防止在被检查的形式加载一个单选按钮? [英] How can I prevent a RadioButton from being checked when the Form loads?
问题描述
似乎是一个Noobie的问题,但我似乎无法阻止我形成了从检查在单选按钮我的一个组合框
作为设计师表示,没有单选按钮检查那里。
下面是差不多所有这种简单的代码。没有要求一个单选按钮在这里或在表单设计器检查
问:有没有方法,以防止任何单选按钮被选中时的形式加载?
公共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;
}
OnShow中无效(对象发件人,EventArgs五){
的foreach(单选弧度的控制){
如果(rad.Checked){
Console.WriteLine(跆拳道?);
}
}
}
无效clickEvent(对象发件人,EventArgs五){
单选弧度=发件人为单选按钮;
如果(弧度!= NULL){
如果(rad.Checked){
如果(RAD == radioButton1){
数据类型= TableDataType.Boolean; //< =这是问题!火灾在表格LOAD
}否则如果(RAD == radioButton2){
数据类型= TableDataType.Character;
}否则如果(RAD == radioButton3){
数据类型= TableDataType.DateTime;
}否则如果(RAD == radioButton4){
数据类型= TableDataType.Decimal;
}否则如果(RAD == radioButton5){
数据类型= TableDataType.Integer;
}否则如果(RAD == radioButton6){
数据类型= TableDataType.String;
}其他{
的回报;
}
button1.Enabled = TRUE;
}
}否则如果(发件人==按钮1){
的DialogResult = DialogResult.OK;
关闭();
}否则如果(发件人==按钮2){
的DialogResult = DialogResult.Cancel;
关闭();
}
}
更新:问题当显示的形式是 radioButton1
被选中:
如果( RAD == radioButton1){
数据类型= TableDataType.Boolean; //< =这是问题!火灾在表格LOAD
}否则如果(RAD == radioButton2){
请确保您的单选按钮不是第一个tabIndex = 0的控制。使确定按钮的tabindex = 0,接着的单选按钮。
Seems like a Noobie question, but I can't seem to prevent my form from checking one of the Radio Buttons in my Group Box
:
As shown in the designer, no Radio Buttons are checked there.
Below is just about all of the code for this simple form. Nothing calls for a Radio Buttons to be checked here or in the form's designer.
Q: Is there a way to prevent any Radio Button from being checked when the form loads?
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();
}
}
UPDATE: The problem is that radioButton1
gets checked when the form is shown:
if (rad == radioButton1) {
DataType = TableDataType.Boolean; // <= HERE IS THE PROBLEM! FIRES ON FORM LOAD
} else if (rad == radioButton2) {
Make sure your radiobuttons are NOT the first tabindex = 0 controls. Make the OK button tabindex=0, followed by the radiobuttons.
这篇关于我怎样才能防止在被检查的形式加载一个单选按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!