Home > Common Problem > How to use radiobutton

How to use radiobutton

(*-*)浩
Release: 2020-01-09 11:13:19
Original
7267 people have browsed it

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 = "对不起,回答错误";
        }
 
    }
}
Copy after login

The above is the detailed content of How to use radiobutton. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template