C#需要动态创建单选按钮并判断用户在Winform中选择了哪个值
我需要基于动态列表动态创建单选按钮。场景就像我在 WinForm 中显示为单选按钮的文件列表。用户单击单选按钮来选择文件并继续。 我尝试做以下示例
for (int i = 0; i < 10; i++)
{
ii = new RadioButton();
ii.Text = i.ToString();
ii.Location = new Point(20, tt);
tt = tt + 20;
panel1.Controls.Add(ii);
}
问题是如何检查用户选择了哪个值?
I need to dynamically create radio buttons based on dynamic list. Scenario is like I have list of files shown as Radio button in WinForm. A user clicks on radio button to select file and move forward.
I tried doing following as an example
for (int i = 0; i < 10; i++)
{
ii = new RadioButton();
ii.Text = i.ToString();
ii.Location = new Point(20, tt);
tt = tt + 20;
panel1.Controls.Add(ii);
}
The problem is how would I check which value got selected by user?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一种简单的方法是使用
RadioButtons
CheckChanged
事件来设置一个变量,该变量指定他们通过使用RadioButtons
选择的文件您可以将其设置为文件本身的文本或Tag
属性吗?例如,
这当然不是最优雅的方式,但它会起作用。
A simple way to do it is by using the
RadioButtons
CheckChanged
event to set a variable that specifies the file that they have chosen by using theRadioButtons
text orTag
property which you could set to be the file itself?e.g.
It's certainly not the most elegant way but it would work.