简体   繁体   English

如何将枚举值设置为 GroupBox 内的单选按钮

[英]How to set enum value to Radio Buttons inside of GroupBox

I have an Enum for two radio buttons.我有两个单选按钮的枚举。 The radio buttons are inside of a Group Box.单选按钮位于组框内。 How do I set UG to a radio button and GRAD to the other one from my Enum.如何从我的枚举中将 UG 设置为单选按钮,将 GRAD 设置为另一个单选按钮。 And How to get which Radio Buttion is Checked in the GrouBox and get the text of the radio Button.以及如何获取在 GrouBox 中选中了哪个 Radio Button 并获取该 radio Button 的文本。 Here's my Enum:这是我的枚举:

public enum RadioBtn
{
    UG,
    GRAG
}

These are the radio buttons这些是单选按钮在此处输入图像描述

you can assign your enum to radio buttons:您可以将枚举分配给单选按钮:

 radioButton1.Text = RadioBtn.GRAG.ToString();
        radioButton2.Text = RadioBtn.UG.ToString();

and in radioButton_CheckedChanged method, you can get the text of those radiobtns: in my sample I set radio button text to label:在 radioButton_CheckedChanged 方法中,您可以获得这些 radiobtns 的文本:在我的示例中,我将单选按钮文本设置为 label:

if (radioButton1.Checked)
        {
            label1.Text = radioButton1.Text;
        }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM