龙盟编程博客 | 无障碍搜索 | 云盘搜索神器
快速搜索
主页 > 软件开发 > C#开发 >

深度看点 C# RadioButton实现方法

时间:2011-04-12 23:18来源:未知 作者:admin 点击:
分享到:
C# RadioButton是大家经常用的一个控件,其属性之多,但是我们只需掌握其中几个就可以了,下面将做一下简单的介绍。 C# RadioButton单选按钮一般用作一个组。 1.C# RadioButton只允许用户从几

C# RadioButton是大家经常用的一个控件,其属性之多,但是我们只需掌握其中几个就可以了,下面将做一下简单的介绍。

C# RadioButton单选按钮一般用作一个组。

1.C# RadioButton只允许用户从几个选项中选择一个,同一个容器中一次只能选择一个按钮;

2.C# RadioButton的Appearance属性:根据的以下两种取值控制外观:
Normal:圆圈+标签,选中后会填充圆圈;
Button:按钮,类似于开关,选中后按下,未选中时凸起;

3.C# RadioButton的Checked属性:
true:选中;
false: 未选中;
4.C# RadioButton的CheckedAlign属性:确定圆圈与标签文本的相对位置。

  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.ComponentModel;  
  4. using System.Data;  
  5. using System.Drawing;  
  6. using System.Text;  
  7. using System.Windows.Forms;  
  8. namespace TestRadioButton  
  9. {  
  10.     public partial class Form1 : Form  
  11.     {  
  12.         public Form1()  
  13.         {  
  14.             InitializeComponent();  
  15.         }  
  16.             private void button1_Click(object sender, EventArgs e)  
  17.         {  
  18.             string checkedRBName = "";  
  19.               
  20.             //取得选中单选按钮的名称  
  21.             if (radioButton1.Checked)  
  22.             {  
  23.                 checkedRBName = radioButton1.Name;  
  24.             }  
  25.             else if (radioButton2.Checked)  
  26.             {  
  27.                 checkedRBName = radioButton2.Name;  
  28.             }  
  29.             else 
  30.             {  
  31.                 checkedRBName = radioButton3.Name;  
  32.             }  
  33.             MessageBox.Show(checkedRBName + " was checked.");  
  34.         }  
  35.     }  
  36. }  

以上就是对C# RadioButton的简单介绍。


精彩图集

赞助商链接