但在具体编程时,取得某种颜色,r,g,b各取什么值,凭空是难以确定的。于是笔者用VB编了一个“RGB调色板”程序,较好地解决了这个问题。此程序李搭顷可作为编程时,取颜色的小工具。
本程序采用了三个水平滚动条控件,分别用于调节r,g,b的值,它们的Max属性设为255;三个标签控件分别用于返回r,g,b的值;一个图片框用于返回相应的颜色。具体的程序如下:
当运行程序后屏幕上出现如图画面。调节三个水平滚动条就返回r,g,b的值和相应的颜枝败色。
Rem RGB调色板程序
Private Sub HScroll1_Change()
Picture1_Click
Label1_Click
End Sub
Private Sub HScroll2_Change()
Picture1_Click
Label2_Click
End Sub
Private Sub HScroll3_Change()
Picture1_Click
Label3_Click
End Sub
Private Sub Label1_Click()
Label1.Caption = HScroll1.Value
End Sub
Private Sub Label2_Click()
Label2.Caption = HScroll2.Value
End Sub
Private Sub Label3_Click()
Label3.Caption = HScroll3.Value
End Sub
Private Sub Picture1_Click()
r = HScroll1.Value
g = HScroll2.Value
b = HScroll3.Value
Picture1.BackColor = RGB(r, g, b)
End Sub
Option ExplicitPrivate Sub Form_Load()
HScroll1.Max = 255: HScroll2.Max = 255: HScroll3.Max = 255
HScroll1.Min = 0: HScroll2.Min = 0: HScroll3.Min = 0
春册HScroll1.Value = 0: HScroll2.Value = 0: HScroll3.Value = 0
Call setColor1
End Sub
Private Sub setColor1()
Dim r As Integer, g As Integer, b As Integer
r = HScroll1.Value: Text1.Text = r
g = HScroll2.Value: Text2.Text = g
b = HScroll3.Value: Text3.Text = b
Label4.BackColor = RGB(r, g, b)
End Sub
Private Sub setColor2()
Dim r As Integer, g As Integer, b As Integer
伏慧 r = Val(Text1.Text): HScroll1.Value = r
g = Val(Text2.Text): HScroll2.Value = g
b = Val(Text3.Text): HScroll3.Value = b
Label4.BackColor = RGB(r, g, b)
End Sub
Private Sub 扒厅宏HScroll1_Change()
Call setColor1
End Sub
Private Sub HScroll2_Change()
Call setColor1
End Sub
Private Sub HScroll3_Change()
Call setColor1
End Sub
Private Sub Text1_Change()
Call setColor2
End Sub
Private Sub Text2_Change()
Call setColor2
End Sub
Private Sub Text3_Change()
Call setColor2
End Sub
你可以画一郑数辩个picturebox然后再上面加一个label改变形状为正方形,边框类型,然后复制一个,变喊缺成数组,然后在毕档打开颜色面板的代码里写上,load
label(i)
label(i)的top
和left值及label(i)的backcolor=rgb(0-255,0-255,0-255)下面的combox的颜色就在label的click事件里写=label(i).backcolor
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)