使用VB控件设计了一个观察RGB颜色变化的小程序。
使用的控件包括:
- 文本框
- 水平滚动条
- 标签
具体界面设计如下:
改变水平滚动条的值,能够对文本框的背景颜色进行调整。
该程序包含一个子过程,用于设置文本框的背景色,名称为changeColor。
三个标签用来显示水平滚动条值得实时变化。
色彩系统采用RGB系统,三个参数分别为三个水平滚动条的值。
具体程序源代码为:
Sub changeColor()
r = HScroll1.Value
g = HScroll2.Value
b = HScroll3.Value
Text1.BackColor = RGB(r, g, b)
End Sub
Private Sub Form_Load()
r = HScroll1.Value
g = HScroll2.Value
b = HScroll3.Value
Text1.BackColor = RGB(r, g, b)
Label1.Caption = "红色分量值:" & HScroll1.Value
Label2.Caption = "绿色分量值:" & HScroll2.Value
Label3.Caption = "黄色分量值:" & HScroll3.Value
End Sub
Private Sub HScroll1_Change()
Label1.Caption = "红色分量值:" & HScroll1.Value
changeColor
End Sub
Private Sub HScroll2_Change()
Label2.Caption = "绿色分量值:" & HScroll2.Value
changeColor
End Sub
Private Sub HScroll3_Change()
Label3.Caption = "黄色分量值:" & HScroll3.Value
changeColor
End Sub