用VB编程实现窗体背景由上至下的颜色逐渐变浅

如题所述

用VB编程实现窗体背景由上至下的颜色逐渐变浅

很多应用程序的安装界面都采用了标准的由蓝到黑渐变的背景,你可以用如下代码实现这种效果
Sub Dither(vForm As Form)
Dim intLoop As Integer
vForm.DrawStyle = vbInsideSolid
vForm.DrawMode = vbCopyPen
vForm.ScaleMode = vbPixels
vForm.DrawWidth = 2
vForm.ScaleHeight = 256
For intLoop = 0 To 255
vForm.Line (0, intLoop)-(Screen.Width, intLoop - 1), RGB(0, 0, 255 - intLoop), B
Next intLoop
End Sub

Private Sub Form_Activate()
Dither Me
End Sub

将窗体的AutoRedraw属性设为True.
如果想得到由红到黑的渐变,只需如下改动:
vForm.Line (0, intLoop)-(Screen.Width, intLoop - 1), RGB(255 - intLoop, 0, 0), B
以下是由绿到黑的渐变效果
vForm.Line (0, intLoop)-(Screen.Width, intLoop - 1), RGB(0,255 - intLoop, 0), B
温馨提示:答案为网友推荐,仅供参考
第1个回答  2008-12-10
直接用picture box!放张用photoshop做的渐变图片最省事!
相似回答