'一个变色文字的例子: Dim r, g, b, redseed, greenseed, blueseed As Integer Private Sub Form_Load() Label1.Caption = "变色的文字" Randomize r = Int(256 * Rnd) g = Int(256 * Rnd) b = Int(256 * Rnd) redseed = 3 greenseed = 5 blueseed = 17 Label1.ForeColor = RGB(r, g, b) Timer1.Interval = 500 Timer1.Enabled = True End Sub Private Sub Timer1_Timer() If r + redseed > 255 Or r + redseed < 0 Then redseed = redseed * -1 If g + greenseed > 255 Or g + greenseed < 0 Then greenseed = greenseed * -1 If b + blueseed > 255 Or b + blueseed < 0 Then blueseed = blueseed * -1 r = r + redseed g = g + greenseed b = b + blueseed Label1.ForeColor = RGB(r, g, b) Label2.Caption = Str(r) & "," & Str(redseed) & "," & Str(g) & "," & Str(greenseed) & "," & Str(b) & "," & Str(blueseed) End Sub如果只想渐隐渐现,修改上面的r、g、b分量就可以了。
关注回复人: ColdMooon(月光寒) 的实现
ColdMooon(月光寒) 用alphablend(正规的方法) 这个怎么使用呢
Option ExplicitPrivate Declare Function AlphaBlend Lib "msimg32" (ByVal hDestDC As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal widthSrc As Long, ByVal heightSrc As Long, ByVal blendFunct As Long) As Boolean 'Type rBlendProps ' tBlendOp As Byte ' tBlendOptions As Byte ' tBlendAmount As Byte ' tAlphaType As Byte 'End Type Dim lTime As Integer, Flag As Integer Sub ShowTransparency(cSrc As PictureBox, cDest As PictureBox, ByVal nLevel As Byte) cDest.Cls With cSrc AlphaBlend cDest.hDC, 0, 0, .ScaleWidth, .ScaleHeight, .hDC, 0, 0, .ScaleWidth, .ScaleHeight, nLevel * &H10000 End With cDest.Refresh End SubPrivate Sub Command1_Click() Flag = 1 Timer1.Enabled = True End SubPrivate Sub Command2_Click() Flag = -1 Timer1.Enabled = True End SubPrivate Sub Timer1_Timer() lTime = lTime + Flag * 5 If lTime > 255 Or lTime < 0 Then Timer1.Enabled = False Exit Sub End If ShowTransparency PicSrc, PicDest, lTime Shape1.Width = PicSrc.Width * lTime / 255 End Sub图形的是这样,文字的不会有问题了吧
2、在timer中用textout
3、用alphablend(正规的方法)
i = IIf(i < 245, i + 10, 0)
Label1.ForeColor = RGB(i, i, i)
End Sub
Dim r, g, b, redseed, greenseed, blueseed As Integer
Private Sub Form_Load()
Label1.Caption = "变色的文字"
Randomize
r = Int(256 * Rnd)
g = Int(256 * Rnd)
b = Int(256 * Rnd)
redseed = 3
greenseed = 5
blueseed = 17
Label1.ForeColor = RGB(r, g, b)
Timer1.Interval = 500
Timer1.Enabled = True
End Sub
Private Sub Timer1_Timer()
If r + redseed > 255 Or r + redseed < 0 Then redseed = redseed * -1
If g + greenseed > 255 Or g + greenseed < 0 Then greenseed = greenseed * -1
If b + blueseed > 255 Or b + blueseed < 0 Then blueseed = blueseed * -1
r = r + redseed
g = g + greenseed
b = b + blueseed
Label1.ForeColor = RGB(r, g, b)
Label2.Caption = Str(r) & "," & Str(redseed) & "," & Str(g) & "," & Str(greenseed) & "," & Str(b) & "," & Str(blueseed)
End Sub如果只想渐隐渐现,修改上面的r、g、b分量就可以了。
用alphablend(正规的方法)
这个怎么使用呢
'Type rBlendProps
' tBlendOp As Byte
' tBlendOptions As Byte
' tBlendAmount As Byte
' tAlphaType As Byte
'End Type
Dim lTime As Integer, Flag As Integer
Sub ShowTransparency(cSrc As PictureBox, cDest As PictureBox, ByVal nLevel As Byte)
cDest.Cls
With cSrc
AlphaBlend cDest.hDC, 0, 0, .ScaleWidth, .ScaleHeight, .hDC, 0, 0, .ScaleWidth, .ScaleHeight, nLevel * &H10000
End With
cDest.Refresh
End SubPrivate Sub Command1_Click()
Flag = 1
Timer1.Enabled = True
End SubPrivate Sub Command2_Click()
Flag = -1
Timer1.Enabled = True
End SubPrivate Sub Timer1_Timer()
lTime = lTime + Flag * 5
If lTime > 255 Or lTime < 0 Then
Timer1.Enabled = False
Exit Sub
End If
ShowTransparency PicSrc, PicDest, lTime
Shape1.Width = PicSrc.Width * lTime / 255
End Sub图形的是这样,文字的不会有问题了吧