深度看點 C# RadioButton實現(xiàn)方法
C# RadioButton是大家經常用的一個控件,其屬性之多,但是我們只需掌握其中幾個就可以了,下面將做一下簡單的介紹。
C# RadioButton單選按鈕一般用作一個組。
1.C# RadioButton只允許用戶從幾個選項中選擇一個,同一個容器中一次只能選擇一個按鈕;
2.C# RadioButton的Appearance屬性:根據(jù)的以下兩種取值控制外觀:
Normal:圓圈+標簽,選中后會填充圓圈;
Button:按鈕,類似于開關,選中后按下,未選中時凸起;
3.C# RadioButton的Checked屬性:
true:選中;
false: 未選中;
4.C# RadioButton的CheckedAlign屬性:確定圓圈與標簽文本的相對位置。
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Text;
- using System.Windows.Forms;
- namespace TestRadioButton
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
- private void button1_Click(object sender, EventArgs e)
- {
- string checkedRBName = "";
- //取得選中單選按鈕的名稱
- if (radioButton1.Checked)
- {
- checkedRBName = radioButton1.Name;
- }
- else if (radioButton2.Checked)
- {
- checkedRBName = radioButton2.Name;
- }
- else
- {
- checkedRBName = radioButton3.Name;
- }
- MessageBox.Show(checkedRBName + " was checked.");
- }
- }
- }
以上就是對C# RadioButton的簡單介紹。
【編輯推薦】