
C# textbox与radiobutton绑定拜托了各位 谢谢
用C#编写,窗体中有一个textbox与9个radiobutton,radiobutton都放在一个groupbox里面,要求当textbox中输入0到9的数字后对应的选...
用C#编写,窗体中有一个textbox与9个radiobutton,radiobutton都放在一个groupbox里面,要求当textbox中输入0到9的数字后对应的选中到0到9的radiobutton。然后安回车,弹出相应radibutton的事件。有例子的最好,能发代码的也可以,谢谢了。
展开
1个回答
展开全部
直接在form窗体上拉一个TextBox和10个RadioButton,代码如下: using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace WindowsFormsApplication1 { public partial class Form1 : Form { string id = null; public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { } private void textBox1_KeyPress(object sender, KeyPressEventArgs e) { if (e.KeyChar >= '0' && e.KeyChar <= '9') { id= "radioButton"+(e.KeyChar + 1-48); (groupBox1.Controls.Find(id, false)[0] as RadioButton).Checked = true; } } private void textBox1_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { MessageBox.Show((groupBox1.Controls.Find(id, false)[0] as RadioButton).Name); } } } }
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询