1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > C# RadioButton: 单选按钮控件

C# RadioButton: 单选按钮控件

时间:2021-09-21 22:30:28

相关推荐

C# RadioButton: 单选按钮控件

【实例】

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

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());}}}

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。