选择单选按钮后,如何使文本框可编辑? [英] How do I make a text box editable when a radio button is selected?

查看:121
本文介绍了选择单选按钮后,如何使文本框可编辑?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一组名为radGrp1的单选按钮.

我在该组中的单选按钮称为rad1,rad2和rad3.

我还有一个文本框txt1.

如何使TXT1编辑选择RAD1时,并选择非可编辑的弧度2或RAD 3?

解决方案
您需要设置 CheckedChanged事件处理程序中txt1 falsetxt1 属性,并将所有其他单选按钮的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 the ReadOnly property of txt1 to false in the CheckedChanged event handler for rad1, and set it to true for the CheckedChanged 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 the Checked property of the radio button!


这篇关于选择单选按钮后,如何使文本框可编辑?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆