设计一个Windows窗体程序,设置程序,其运行结果如下图所示。一个标签控件的Text属性为“缩放”两个字,它的字体大小取决于垂直滚动条的值(Maximum=72,Minimum=8),并在另一个标签上显示当前的字号。
提示:如果设置标签的字体为12号,则用如下代码:
label1.Font = new Font(label1.Font.Name, 12);
对于以上问题,首先应创建Windows应用程序项目,在窗体上添加2个标签控件(Label1的Text属性设置为“缩放”),一个垂直滚动条控件(VScrollBar),其Maximum属性设置为72,Minimum属性设置为8。
源代码如下:
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 中期测试第三题
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void vScrollBar1_Scroll(object sender, ScrollEventArgs e)
{
label1.Font = new Font(label1.Font.Name, vScrollBar1.Value);
label2.Text = "字体的大小是"+vScrollBar1.Value ;
}
}
}
运行结果如图所示: