简单的单选按钮问题 [英] Simple Radio Button Question

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

问题描述

我知道这应该很简单,但是我似乎在任何地方都找不到答案.

在VB6中,我似乎想起了能够创建单选按钮数组的事实(实际上,我认为必须如此),以便测试时间就像在整个数组中扫描一样简单.

我不想使用分组框,因为它在外观上与我的设计不符...因此,如何在面板上创建一个简单的单选按钮分组,当用户单击保存按钮时可以对其进行扫描我创建的目的是确定他们想要什么选项(并且他们已经选择了至少一个选项).

谢谢.

I know this should be simple but I can''t seem to find the answer anywhere.

In VB6 I seem to recall being able to create an array of Radio Buttons (in fact I think it had to be) so that testing when was as simple as scanning across the array.

I don''t want to use a group box because that doesn''t fit visually with my design ... so how can I create a simple grouping of Radio buttons on my panel that I can scan when the user hits the save button I''ve created to determine what option they want (and that they''ve selected at least one option).

Thanks.

推荐答案

您可以创建一个没有边框的面板,然后将单选按钮放入其中.那时,您可以枚举子控件.就我个人而言,我只是维护一个变量,该变量指示给定组中当前选中的单选按钮.
You can create a Panel with no border, and put the radio buttons into that. At that point you can just enumerate the child controls. Personally, I simply maintain a single variable that indicates the currently selected radio button in a given group.


我实际上在另一个站点上找到了一篇文章,描述了完成此工作的方式.

创建1个事件处理程序,然后更改处理程序"部分以列出要处理的所有单选按钮.

这样,只要选中任何一个单选按钮,就只需要一个事件处理程序,就可以更新变量以显示当前被选中的变量.

将代码放入表单构造函数中,将允许您将单个单选按钮映射到单选按钮数组,从而允许您使用该数组迭代按钮.

虽然不像VB6那样琐碎,但是仍然可以做到.
I actually found an article on another site that describes the way to make this work.

You create 1 event handler and then change the Handles portion to list all of the radio buttons you want handled.

This way you only need a single event handler whenever any of the radio buttons is checked and you can update a variable to show which one is currently selected.

Putting code into the forms constructor will allow you to map the individual radio buttons to an array of radio buttons allowing you to iterate over the buttons using the array.

Not quite as trivial as it was in VB6 but it can still be done.


这篇关于简单的单选按钮问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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