动态创建面板中动态创建单选按钮的分组 [英] Grouping of Dynamically create radio button in Dynamically created Panels

查看:74
本文介绍了动态创建面板中动态创建单选按钮的分组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

我在一个主面板中使用for loop动态创建了6个面板.在每个面板中,我创建了1个单选按钮.我想对所有六个单选按钮进行分组.因此用户一次只能选择1个单选按钮.

任何人都可以帮助我.

在此先感谢.

Hello,

I have created 6 panel dynamically in one main panel, using for loop.in each panel i have created 1 radio button.I want to grouping of all six radio button. so user can only select 1 radio button at a time.

any one can help me.

Thanks in advance.

推荐答案

为此,请使用控件System.Windows.Forms.GroupBox,请参阅 ^ ].

在动态创建过程中,使用Control.Controls.AddRadioButton的所有互斥选项添加为GroupBox的同一实例的子代,或者将每个RadioButton的属性Control.Parent的值设置为GroupBox的相同实例,请参阅:
http://msdn.microsoft.com/en-us/library/system. windows.forms.radiobutton.aspx [ ^ ].

动态执行此操作并不比您已经完成的难.



顺便说一句,您可以使用Panel作为单选按钮的容器来执行完全相同的操作.使用GroupBox实例的唯一原因是给该组一个通用的文本标签(属性GroupBox.Text).您也可以使用&"标签文本的一个字符的前缀(就像您对常规标签(Label类)所做的那样;然后它将用作整个组的热键.

—SA
For this purpose, use the control System.Windows.Forms.GroupBox, please see http://msdn.microsoft.com/en-us/library/system.windows.forms.groupbox.aspx[^].

During dynamic creation, add all mutually exclusive choices by RadioButton as children of the same instance of GroupBox using Control.Controls.Add or by setting value of the property Control.Parent of each RadioButton to the same instance of GroupBox, see:
http://msdn.microsoft.com/en-us/library/system.windows.forms.radiobutton.aspx[^].

Doing it dynamically is not harder than what you already done.



By the way, you could do exact same thing using Panel as a container for your radio buttons. The only reason to use an instance of the GroupBox is to give a common text label to the group (the property GroupBox.Text). You can also use "&" prefix to one character of a label text (as you would do with usual labels (Label class); then it will serve as a hot key for a whole group.

—SA


这篇关于动态创建面板中动态创建单选按钮的分组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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