如何获得在组框中选中的单选按钮? [英] How to get a checked radio button in a groupbox?

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

问题描述

我有很多的单选按钮的组框。通常,我会检查每个单选按钮单独使用如果radiobutton1.Checked = TRUE,则

I have a lot of radio buttons in a groupbox. Normally I will check each radio button individually using If radiobutton1.Checked = True Then.

不过,我想,也许有聪明的办法来检查哪个单选按钮被选中的组框。你知道吗?

But I think maybe there is smart way to check which radio button being checked in a groupbox. Any idea?

推荐答案

试试这个

Dim rButton As RadioButton = 
        GroupBox1.Controls
       .OfType(Of RadioButton)
       .FirstOrDefault(Function(r) r.Checked = True)

这将返回经过单选分组框

请注意,这是一个LINQ查询,而且必须有

Note that this is a LINQ query, and you must have

Imports System.Linq

如果你不这样做,你的IDE /编译器可能表明 OfType 不是 System.Windows.Forms.Control.ControlCollection <成员/ code>

If you do not, your IDE/Compiler may indicate that OfType is not a member of System.Windows.Forms.Control.ControlCollection

这篇关于如何获得在组框中选中的单选按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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