星空网 > 软件开发 > ASP.net

C# WinForm的练习

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

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

C#  WinForm的练习

 

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

C#  WinForm的练习

C#  WinForm的练习  

代码如下:

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;    }  }}

结果如下图:

C#  WinForm的练习

 

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

 




原标题:C# WinForm的练习

关键词:C#

C#
*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

大江国际货运:https://www.goluckyvip.com/tag/101019.html
FunPinPin:https://www.goluckyvip.com/tag/10102.html
国际货运询价:https://www.goluckyvip.com/tag/101020.html
大运国际货运:https://www.goluckyvip.com/tag/101021.html
创荣国际物流:https://www.goluckyvip.com/tag/101022.html
ems国际快递客服:https://www.goluckyvip.com/tag/101023.html
千岛湖绿城度假酒店的简介:https://www.vstour.cn/a/363185.html
深圳大湾区游轮夜景 深圳大湾区游轮夜景图:https://www.vstour.cn/a/363186.html
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流