加入一個TextBox控件,一個Command控件
目前創(chuàng)新互聯(lián)已為1000多家的企業(yè)提供了網(wǎng)站建設、域名、虛擬空間、成都網(wǎng)站托管、企業(yè)網(wǎng)站設計、和龍網(wǎng)站維護等服務,公司將堅持客戶導向、應用為本的策略,正道將秉承"和諧、參與、激情"的文化,與客戶和合作伙伴齊心協(xié)力一起成長,共同發(fā)展。
代碼:
Private Declare Function GetPixel Lib "gdi32" (ByVal hDC As Long, ByVal X As Long, ByVal Y As Long) As Long
Private Declare Function GetWindowDC Lib "user32" (ByVal hWnd As Long) As Long
Private Sub Command1_Click()
Dim Color As Long
WindowDC = GetWindowDC(0) '獲取屏幕的設備場景
Color = GetPixel(WindowDC, 500, 100) '獲指定點的顏色
'分解RGB顏色值
R = (Color Mod 256) '紅色
b = (Int(Color \ 65536)) '藍色
G = ((Color - (b * 65536) - R) \ 256) '綠色
Text1.BackColor = RGB(R, G, b)
End Sub
R/G/B值最小是0最大是255屬Byte值類型
Dim cr As Color = 控件.BackColor '獲取控件背景色
Dim alpha As Byte = cr.A '透明度
Dim R As Byte = cr.R 'R值
Dim G As Byte = cr.G 'G值
Dim B As Byte = cr.B 'B值
Dim outAcr As Color = Color.FromArgb(alpha, R, G, B) '創(chuàng)建帶有透明通道的ARGB顏色
Dim outcr As Color = Color.FromArgb(R, G, B) '創(chuàng)建不透明的RGB顏色
將控件的背景色設為透明即可: 如Label1.BackColor=Color.Transparent 當然,還有別的方式可使底色透明,你自已琢磨一下。
VB可使用Point方法來獲取圖片指定點的顏色。
Point 方法
按照長整數(shù),返回在 Form 或 PictureBox 上所指定磅的紅-綠-藍 (RGB) 顏色。
語法
object.Point(x, y)
'窗體判色代碼:
Private Sub Form1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Text1 = X
Text2 = Y
Text3 = Point(X, Y)
Text4 = (Val(Text3) Mod 65536) Mod 256 'Red
Text5 = (Val(Text3) Mod 65536) \ 256 'Green
Text6 = Val(Text3) \ 65536 'Blue
Shape1.FillColor = RGB(Val(Text4), Val(Text5), Val(Text6))
End Sub
'PictureBox判色代碼:
Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Text1 = X
Text2 = Y
Text3 = Picture1.Point(X, Y)
Text4 = (Val(Text3) Mod 65536) Mod 256 'Red
Text5 = (Val(Text3) Mod 65536) \ 256 'Green
Text6 = Val(Text3) \ 65536 'Blue
Shape1.FillColor = RGB(Val(Text4), Val(Text5), Val(Text6))
End Sub