选择单选按钮后,如何使文本框可编辑? [英] How do I make a text box editable when a radio button is selected?
问题描述
我有一组名为radGrp1的单选按钮.
我在该组中的单选按钮称为rad1,rad2和rad3.
我还有一个文本框txt1.
如何使TXT1编辑选择RAD1时,并选择非可编辑的弧度2或RAD 3?
您需要设置CheckedChanged
事件处理程序中txt1
到false
的txt1
属性,并将所有其他单选按钮的CheckedChanged
事件处理程序设置为true
.
示例1(设置ReadOnly属性)
void Foo() { txt1.ReadOnly = true; // this makes the text box read-only (uneditable) txt1.ReadOnly = false; // this makes the text box editable. }
示例2(将单选按钮连接到现有事件处理程序)
void HookItUp() { rad1.Click += new EventHandler(this.rad1_CheckedChanged); }
如果使用任何Visual Studio IDE,则只需双击单选按钮即可生成CheckedChanged处理程序.请记住,当单选按钮的选中状态为SET和UNSET时会触发此事件,因此请始终检查单选按钮的Checked
属性!
I have a group of radio buttons called radGrp1.
My radio buttons within the group are called rad1, rad2 and rad3.
I also have a text box, txt1.
How do I make txt1 editable when rad1 is selected, and non-editable when rad 2 or rad 3 are selected?
You will need to set theReadOnly
property oftxt1
tofalse
in theCheckedChanged
event handler forrad1
, and set it totrue
for theCheckedChanged
event handler for all the other radio buttons.
Example 1 (Setting the ReadOnly property)
void Foo() { txt1.ReadOnly = true; // this makes the text box read-only (uneditable) txt1.ReadOnly = false; // this makes the text box editable. }
Example 2 (Hooking up a radio button to an existing event handler)
void HookItUp() { rad1.Click += new EventHandler(this.rad1_CheckedChanged); }
If you are using any of the Visual Studio IDEs you should only need to double-click the radio button to generate the CheckedChanged handler. Remember this event gets fired when the checked state of the radio button is SET and UNSET, so always check theChecked
property of the radio button!
这篇关于选择单选按钮后,如何使文本框可编辑?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!