首页 常见问题 radiobutton怎么用

radiobutton怎么用

Jan 09, 2020 am 11:13 AM

radiobutton怎么用

RadioButton控件                                      (推荐学习:phpstorm

单选按钮,当与其他单选按钮成对出现时,允许用户从一组选项中选择单个选项。也就是说,当同一个容器中(Form、Panel、GroupBox、PictureBox等)存在两个以上的单选按钮时,只能有一个被选中。

但不在同一个容器中的几组单选按钮彼此不关联,是可以有多个被选中的。

属性

Checked属性:最重要的属性之一,该属性是一个布尔类型的值,如果被选中,Checked的值为true,否则为false。常用于判断选项是否被选中。

事件

这两个控件的事件有很多,但主要用到的事件只有一个,那就是CheckedChanged事件。该事件在”Checked”属性发生改变时发生。

用法(单项选择)

cj-395.png

后台代码:

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 = "对不起,回答错误";
        }
 
    }
}
登录后复制

以上是radiobutton怎么用的详细内容。更多信息请关注PHP中文网其他相关文章!

本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn

热AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover

AI Clothes Remover

用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool

Undress AI Tool

免费脱衣服图片

Clothoff.io

Clothoff.io

AI脱衣机

AI Hentai Generator

AI Hentai Generator

免费生成ai无尽的。

热工具

记事本++7.3.1

记事本++7.3.1

好用且免费的代码编辑器

SublimeText3汉化版

SublimeText3汉化版

中文版,非常好用

禅工作室 13.0.1

禅工作室 13.0.1

功能强大的PHP集成开发环境

Dreamweaver CS6

Dreamweaver CS6

视觉化网页开发工具

SublimeText3 Mac版

SublimeText3 Mac版

神级代码编辑软件(SublimeText3)