如何用VB给Form背景产生渐变效果的颜色?或者如何把画出的平行线紧紧的靠在一起,就是没有间距的那种。
补充:RGB()可以使用变量吗?如何使用?
追问:能解释原理么?是在每一条线上的渐变,还是线与线之间的渐变?本人菜鸟,复杂了看不懂唉
补充:RGB()可以使用变量吗?如何使用?
追问:能解释原理么?是在每一条线上的渐变,还是线与线之间的渐变?本人菜鸟,复杂了看不懂唉
答案:楼上的又慢,又不能充满窗口,看这个两种效果的:
Sub VDither(startForm As Form)
'垂直渐变
Dim intLoop As Integer
startForm.DrawStyle = vbInsideSolid
startForm.DrawMode = vbCopyPen
startForm.ScaleMode = vbPixels
startForm.DrawWidth = 2
startForm.AutoRedraw = True
For intLoop = 0 To startForm.ScaleHeight
startForm.Line (0, intLoop)-(startForm.ScaleWidth, intLoop), RGB(Abs(255 - intLoop), Abs(255 - intLoop), Abs(255 - intLoop)), B
Next intLoop
End Sub
Sub HDither(startForm As Form)
'水平渐变
Dim intLoop As Integer
startForm.DrawStyle = vbInsideSolid
startForm.DrawMode = vbCopyPen
startForm.ScaleMode = vbPixels
startForm.DrawWidth = 2
startForm.AutoRedraw = True
For intLoop = 0 To startForm.Width
startForm.Line (intLoop, 1)-(intLoop, startForm.Height), RGB(Abs(255 - intLoop), 255, 255), B
'从白色渐变到蓝色
Next intLoop
End Sub
Private Sub Form_Resize()
VDither Form1
End Sub
其他:Private Type RGB_Type
R As Long
G As Long
B As Long
End Type
Private Function Percent(a As Variant, _
ByVal B As Variant) As Double
'calculate percentage given two numbers(using Variant allows you st send any type
'Provided for this demo
'you probably have your own percent function already
Dim c As Single
If a > B Then
a = B
End If
If B = 0 Then
Percent = 0
Exit Function
End If
c = Int(a / B * 100)
If c > 100 Then
c = 100
End If
Percent = c
End Function
Private Function RGBPercentage(lngStartColor As Long, _
lngEndColor As Long, _
ByVal phase As Single) As Long
'generate a colour that is a certain percentage between the 2 input colours
Dim Scols As RGB_Type
Dim Ecols As RGB_Type
'break the colours up
Scols = ToRGB(lngStartColor)
Ecols = ToRGB(lngEndColor)
'generate the new colour
With Scols
RGBPercentage = RGB(.R + ((Ecols.R - .R) * phase / 100), .G + ((Ecols.G - .G) * phase / 100), .B + ((Ecols.B - .B) * phase / 100))
End With 'Scols
End Function
Private Function ToRGB(ByVal LngColor As Long) As RGB_Type
'break a long colour value into its RGB parts
'there are lots of ways to do this (many faster than this)
'this is just the one I had stored in my templates folder
Dim ColorStr As String
ColorStr = Right$("000000" & Hex$(LngColor), 6)
With ToRGB
.R = Val("&h" & Right$(ColorStr, 2))
.G = Val("&h" & Mid$(ColorStr, 3, 2))
.B = Val("&h" & Left$(ColorStr, 2))
End With
End Function
Private Sub Form_Resize()
Dim X As Long
For X = 1 To Me.Width
Me.Line (X, 0)-(X, Me.Height), RGBPercentage(RGB(255, 255, 0), RGB(255, 0, 0), Percent(X, Me.Width))
Next X
End Sub
上一个:高手们好,我是vb新手最近设计了一个程序,面板主要由一个选项卡控件构成,现在遇到了下面这样的问题:
下一个:VB中怎么先运行模块中内容再运行窗体中内容