深度看點(diǎn) C# RadioButton實(shí)現(xiàn)方法
C# RadioButton是大家經(jīng)常用的一個(gè)控件,其屬性之多,但是我們只需掌握其中幾個(gè)就可以了,下面將做一下簡單的介紹。
C# RadioButton單選按鈕一般用作一個(gè)組。
1.C# RadioButton只允許用戶從幾個(gè)選項(xiàng)中選擇一個(gè),同一個(gè)容器中一次只能選擇一個(gè)按鈕;
2.C# RadioButton的Appearance屬性:根據(jù)的以下兩種取值控制外觀:
Normal:圓圈+標(biāo)簽,選中后會(huì)填充圓圈;
Button:按鈕,類似于開關(guān),選中后按下,未選中時(shí)凸起;
3.C# RadioButton的Checked屬性:
true:選中;
false: 未選中;
4.C# RadioButton的CheckedAlign屬性:確定圓圈與標(biāo)簽文本的相對位置。
- 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的簡單介紹。
【編輯推薦】