C#界面设计之复选按钮与单选按钮的使用实例

还是先看效果再看代码吧!
C#界面设计之复选按钮与单选按钮的使用实例_第1张图片

主要代码如下:

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 CheckRadioButtons
{
    public partial class Form1 : Form
    {
        public Form1( )
        {
            InitializeComponent( );
        }

        private void buttons_CheckedChanged(object sender, EventArgs e)
        {
            string weeks = "";
            weeks += ckbWeek1.Checked ? "星期一 " : "";
            weeks += ckbWeek2.Checked ? "星期二 " : "";
            weeks += ckbWeek3.Checked ? "星期三 " : "";
            weeks += ckbWeek4.Checked ? "星期四 " : "";
            weeks += ckbWeek5.Checked ? "星期五 " : "";
            weeks += ckbWeek6.Checked ? "星期六 " : "";
            weeks += ckbWeek7.Checked ? "星期日 " : "";
            string sport = "";
            sport += rbSword.Checked ? "击剑 " : "";
            sport += rbJump.Checked ? "跳水 " : "";
            sport += rbTiCao.Checked ? "体操 " : "";
            string jiangpai = "";
            jiangpai += rbGold.Checked ? "金牌 " : "";
            jiangpai += rbSliver.Checked ? "银牌 " : "";
            jiangpai += rbTong.Checked ? "铜牌 " : "";

            this.lbHint.Text = weeks + sport + jiangpai;
        }

    }
}

主要是控件的.Checked的学习,这个才是重点!

你可能感兴趣的:(C#学习笔记)