【程序功能】 本程序实现如下功能:在 windows 窗体中显示水平滚动条控件;当改变滚动条控件的数值的时候,窗体的前景颜色发生相应的变化。 【操作要求】 新建并保存项目:在 visual studio .NET 中,新建一个 visual c#windows 应用程序项目,名称设置为 Test4_4 ,贼之设置为考生文件夹。 1. 设计窗体: 在窗体中添加三个 lable 控件、三个 HScrollBar 控件,设计的窗体及控件的 Tab 件顺序如图 4-4a 所示,各个控件的 name 和 test 属性安装表 4-4 进行设置。 2. 在设计时设置控件的属性: 设置控件 HScrollBar1 、 HScrollBar2 、 HScrollBar3 控件值的变化范围均为 0~255 之间,控件 lable4 的字体为三加粗宋体,其余保持默认设置。 3. 在运行时改变控件的属性: 为控件 HScrollBar1 、 HScrollBar2 、 HScrollBar3 添加数值改变事件,在处理代码中改变窗体的前景颜色。窗体的背景颜色随控件 HScrollBar1 、 HScrollBar2 、 HScrollBar3 的数值变化而变化 : this .ForeColor = Color .FromArgb(hScrollBar1.Value, hScrollBar2.Value, hScrollBar3.Value); 4. 程序设计完成之后进行编译,生成项目的 EXE 可执行文件 【执行结果】 运行程序显示窗体,可通过改变各个滚动条控件的数值来改变窗体的前景颜色。例如,当控件 HScrollBar1 、 HScrollBar2 、 HScrollBar3 均位大值时,窗体前景颜色为白色,当控件 HScrollBar1 位大值而控件 HScrollBar3 和 HScrollBar2 位小值时,窗体前景颜色为红色,如图 4-4b 所示。