gpt4 book ai didi

c# - 如何从组框中获取选中哪个单选按钮?

转载 作者:可可西里 更新时间:2023-11-01 07:50:27 25 4
gpt4 key购买 nike

我有这些组框:

Enter image description here

我想根据单选按钮的检查真实状态运行一些代码,例如:

string chk = radiobutton.nme; // Name of radio button whose checked is true
switch(chk)
{
case "Option1":
// Some code
break;

case "Option2":
// Some code
break;

case "Option3":
// Some code
break;
}

有什么直接的方法可以让我只能得到选中的单选按钮的名称吗?

最佳答案

您可以找到所有选中的 RadioButtons,例如

var buttons = this.Controls.OfType<RadioButton>()
.FirstOrDefault(n => n.Checked);

另请查看 CheckedChanged事件。

Occurs when the value of the Checked property changes.

关于c# - 如何从组框中获取选中哪个单选按钮?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18547326/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com