C#程序设计(十八)----文字样式发生变化

* 程序的版权和版本声明部分
* Copyright (c) 2012, 烟台大学计算机学院学生
* All rights reserved.

* 作 者: 刘镇
* 完成日期: 2012 年 11 月 10 日
* 版 本 号: 3.018

* 对任务及求解方法的描述部分

* 问题描述:

1)复选框中文字在左边;2)最下部为水平滚动条。水平滚动条最小值为4、最大值为72;且在窗体Load事件中通过代码设置;3)单击任何复选框,标签上文字样式都发生变化;4)单击任意单选按钮,标签上文字字体都发生改变;5)拖动水平滚动条,标签上文字大小发生变化

 

 

*代码部分:

 

 

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

        private void hScrollBar1_Scroll(object sender, ScrollEventArgs e)
        {
            label1.Font = new Font(label1.Font.Name, hScrollBar1.Value);
        }

        private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {
            label1.Font = new Font(label1.Font.Name, label1.Font.Size, checkBox1.Checked ? label1.Font.Style | FontStyle.Italic : label1.Font.Style ^ (FontStyle.Italic));
        }

        private void checkBox2_CheckedChanged(object sender, EventArgs e)
        {
            label1.Font = new Font(label1.Font.Name, label1.Font.Size, checkBox1.Checked ? label1.Font.Style | FontStyle.Underline : label1.Font.Style ^ (FontStyle.Underline));
        }

        private void checkBox3_CheckedChanged(object sender, EventArgs e)
        {
            label1.Font = new Font(label1.Font.Name, label1.Font.Size, checkBox1.Checked ? label1.Font.Style | FontStyle.Bold : label1.Font.Style ^ (FontStyle.Bold));
        }

        private void radioButton1_CheckedChanged(object sender, EventArgs e)
        {
            label1.Font = new Font("黑体", label1.Font.Size, label1.Font.Style);
        }

        private void radioButton2_CheckedChanged(object sender, EventArgs e)
        {
            label1.Font = new Font("楷体_GB2312", label1.Font.Size, label1.Font.Style);
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            this.Text = "修改文字窗口";
        }
    }
}


 

 

测试结果:

 

 

心得经验:

 

简言之就是处理Font();

其次是将GroupBox运用其中;

剩下的就是对属性的修改,加上事件触发,就完成了。

 

 

 

 

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章