【实例】
完成选择用户权限的操作,并在消息框中显示所选的权限名
Form1.cs
using System;using System.Collections.Generic;using ponentModel;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 (radioButton3.Checked){msg = radioButton3.Text;}MessageBox.Show("您选择的权限是:" + msg, "提示");}}}
Program.cs
using System;using System.Collections.Generic;using System.Linq;using System.Windows.Forms;namespace RadioButton{static class Program{/// <summary>/// 应用程序的主入口点。/// </summary>[STAThread]static void Main(){Application.EnableVisualStyles();Application.SetCompatibleTextRenderingDefault(false);Application.Run(new Form1());}}}