十年网站开发经验 + 多家企业客户 + 靠谱的建站团队
量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决
创建一个Time控件、Label1控件,代码如下:
目前创新互联建站已为千余家的企业提供了网站建设、域名、雅安服务器托管、成都网站托管、企业网站设计、建邺网站维护等服务,公司将坚持客户导向、应用为本的策略,正道将秉承"和谐、参与、激情"的文化,与客户和合作伙伴齐心协力一起成长,共同发展。
Private Sub Form_Load()
Timer1.Interval = 500
End Sub
Private Sub Timer1_Timer()
a = Int(Rnd * 256)
b = Int(Rnd * 256)
c = Int(Rnd * 256)
Label1.ForeColor = RGB(a, b, c)
End Sub
就可以实现Label1控件的字体随机颜色变换。
Dim c As Color '新生成的颜色
Dim r As Byte 'RED
Dim g As Byte 'Green
Dim b As Byte 'Blue
Dim a As Byte 'Alpha 分量值
a = Button1.BackColor.A
r = Button1.BackColor.R
g = Button1.BackColor.G
b = Button1.BackColor.B
Dim rnd As New Random '生成随机数
Dim i As Integer
i = rnd.Next(-10, 10)
r = r + IIf(r + i 255, -i, i)
i = rnd.Next(-10, 10)
g = g + IIf(g + i 255, -i, i)
i = rnd.Next(-10, 10)
b = b + IIf(b + i 255, -i, i)
c = Color.FromArgb(a, r, g, b)
写一个函数 如 随机颜色
随机1-4 int(rnd*4) 赋值给一个变量如a
然后 select case a
case 1 红
case 2 黄
case 3 蓝
case 4 绿
把这个函数返回值设置为颜色的 整数形式
最后在你使用的地方,某某.color=随机颜色()
Private Sub Form_Click()
Randomize Timer
BackColor = RGB(Rnd * 256, Rnd * 256, Rnd * 256)
End Sub
'这是改变窗体背景颜色的过程代码。
这个问题的本质就是随机二字,无论c/s还是b/s里面的label1 ,只要随机设置字体颜色属性即可。而相关属性我相信您肯定知道,关键是怎样随机。vb.net里面有一个随机函数,只要利用该随机函数,随机生成相应的颜色即可,然后把随机颜色赋值给label的属性
我有个笨办法,先用API抓图到内存里,然后再在根据你点鼠标的屏幕工作区坐标,去那图里取色。
-----------------------
'抓图所需的API
Private Declare Function CreateCompatibleDC Lib "GDI32" (ByVal hDC As Integer) As Integer
Private Declare Function CreateCompatibleBitmap Lib "GDI32" (ByVal hDC As Integer, ByVal nWidth As Integer, ByVal nHeight As Integer) As Integer
Private Declare Function SelectObject Lib "GDI32" (ByVal hDC As Integer, ByVal hObject As Integer) As Integer
Private Declare Function BitBlt Lib "GDI32" (ByVal srchDC As Integer, ByVal srcX As Integer, ByVal srcY As Integer, ByVal srcW As Integer, ByVal srcH As Integer, ByVal desthDC As Integer, ByVal destX As Integer, ByVal destY As Integer, ByVal op As Integer) As Integer
Private Declare Function DeleteDC Lib "GDI32" (ByVal hDC As Integer) As Integer
Private Declare Function DeleteObject Lib "GDI32" (ByVal hObj As Integer) As Integer
Declare Function GetDC Lib "user32" Alias "GetDC" (ByVal hwnd As Integer) As Integer
Const SRCCOPY As Integer = HCC0020
'抓图的部分
Dim hDC, hMDC As Integer
Dim hBMP, hBMPOld As Integer
Dim sw, sh As Integer
hDC = GetDC(0)
hMDC = CreateCompatibleDC(hDC)
sw = Screen.PrimaryScreen.Bounds.Width
sh = Screen.PrimaryScreen.Bounds.Height
hBMP = CreateCompatibleBitmap(hDC, sw, sh)
hBMPOld = SelectObject(hMDC, hBMP)
BitBlt(hMDC, 0, 0, sw, sh, hDC, 0, 0, SRCCOPY)
hBMP = SelectObject(hMDC, hBMPOld)
Dim bmp As Bitmap = Image.FromHbitmap(New IntPtr(hBMP))
DeleteDC(hDC)
DeleteDC(hMDC)
DeleteObject(hBMP)
......
'取点的颜色
bmp.GetPixel(e.X, e.Y)
----------------------------
关键就是这些你自己组合吧,你分给的太少了,很麻烦,恕我不帮你改全了。如果要仔细帮你改,请另开高分贴,不要用新马甲来