How to use radiobutton
##RadioButton Control Buttons, when presented in pairs, allow the user to select a single option from a set of options. That is to say, when there are more than two radio buttons in the same container (Form, Panel, GroupBox, PictureBox, etc.), only one can be selected. But several sets of radio buttons that are not in the same container are not related to each other, and multiple ones can be selected.
Attribute
Checked attribute: One of the most important attributes, this attribute is a Boolean value. If it is selected, the value of Checked is true, otherwise it is false. Often used to determine whether an option is selected.
Events
There are many events for these two controls, but there is only one event that is mainly used, and that is the CheckedChanged event. This event occurs when the "Checked" property changes.
Usage (single choice)
##Backend code:
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace RadioButton { public partial class RadioButton : Form { public RadioButton() { InitializeComponent(); } private void radioButton1_CheckedChanged(object sender, EventArgs e) { label2.ForeColor = Color.Black; if (radioButton1.Checked) label2.Text = "你的答案是:" + radioButton1.Text; } private void radioButton2_CheckedChanged(object sender, EventArgs e) { label2.ForeColor = Color.Black; if (radioButton2.Checked) label2.Text = "你的答案是:" + radioButton2.Text; } private void radioButton3_CheckedChanged(object sender, EventArgs e) { label2.ForeColor = Color.Black; if (radioButton3.Checked) label2.Text = "你的答案是:" + radioButton3.Text; } private void radioButton4_CheckedChanged(object sender, EventArgs e) { label2.ForeColor = Color.Black; if (radioButton4.Checked) label2.Text = "你的答案是:" + radioButton4.Text; } private void button1_Click(object sender, EventArgs e) { label2.ForeColor = Color.Red; if (radioButton2.Checked) label2.Text = "恭喜你,回答正确"; else label2.Text = "对不起,回答错误"; } } }
The above is the detailed content of How to use radiobutton. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

