C# RadioButton: 单选按钮控件

该博客介绍了如何在C#中利用RadioButton控件来实现用户权限的选择操作。通过示例代码展示了如何获取用户选定的权限,并在消息框中展示所选的权限名称。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

【实例】

              完成选择用户权限的操作,并在消息框中显示所选的权限名

Form1.cs

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace RadioButton
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        //单击“确定”按钮的事件
        private void button1_Click(object sender, EventArgs e)
        {
            /*
             *Checked 属性可用于判断单选按钮是否被选中。
             *如果该属性的返回值为 True,则代表选中;如果返回值为 False,则表示未选中。
             */
            string msg = "";
            if (radioButton1.Checked)
            {
                msg = radioButton1.Text;
            }
            else if (radioButton2.Checked)
            {
                msg = radioButton2.Text;
            }
            else if (radi
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值