C# WinForm的练习

今天写了一个WinForm的练习,将源代码贴出来和大家一起学习学习。

首先:按照下图将一个button控件、三个RadioButton控件、三个CheckBox控件、一个Label控件和一个TrackBar控件。

 

其次:如图  进度条是用来控制    的字体大小的。

  

代码如下:

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 Ch12Ex04
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        /// <summary>
        /// 点击button按钮触发事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button1_Click(object sender, EventArgs e)
        {
            string RadioButton = null;
            string CheckBoxs = new string('\0', 0);
            if (radioButton1.Checked)
            {
                RadioButton = radioButton1.Text;
            }
            if (radioButton2.Checked)
            {
                RadioButton = radioButton2.Text;
            }
            if (radioButton3.Checked)
            {
                RadioButton = radioButton3.Text;
            }
            if (checkBox1.Checked)
            {
                CheckBoxs += checkBox1.Text + " ";
            }
            if (checkBox2.Checked)
            {
                CheckBoxs += checkBox2.Text + " ";
            }
            if (checkBox3.Checked)
            {
                CheckBoxs += checkBox3.Text + " ";
            }
            if (CheckBoxs.Length == 0)
            {
                CheckBoxs = "没有复选框被选中";
            }
            else
            {
                CheckBoxs = "复选框  " + CheckBoxs + "  被选中";
            }
            if (RadioButton==null)
            {
                RadioButton = "没有单选框被选中";
            }
            else
            {
                RadioButton = "单选框  " + RadioButton + "  被选中";
            }

            MessageBox.Show(RadioButton + Environment.NewLine + Environment.NewLine + CheckBoxs);
            this.Close();
        }
        /// <summary>
        /// trackBar1_Scroll方法是用来控制text文本的大小的
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void trackBar1_Scroll(object sender, EventArgs e)
        {
            //文本字体
            FontFamily oldFontFamily = this.label1.Font.FontFamily;
            //样式
            FontStyle oldFontStyle = this.label1.Font.Style;
            //获得滚动条当前的值
            float fontSize = this.trackBar1.Value;
            Font newFont = new Font(oldFontFamily, fontSize, oldFontStyle);
            this.label1.Font = newFont;
        }
    }
}

结果如下图:

 

到了这里基本上这个程序就运行完毕了。

 

转载于:https://www.cnblogs.com/hp-discuz/p/5054883.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值