How to get a checked radio button in a groupbox?

前端 未结 11 1280
谎友^
谎友^ 2020-12-03 07:46

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

11条回答
  •  我在风中等你
    2020-12-03 08:37

    try this

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

    this will return the Checked RadioButton in a GroupBox

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

    Imports System.Linq
    

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

提交回复
热议问题