Make your own free website on Tripod.com

Make Gradient Forms

'This example will make a Form/Picture Box with dithered background, like some of the
'install programs. You can do the same to Picture Box.
'Set the Form AutoRedraw property to True.
'Insert the following code to your form:

Sub Gradient(TheObject As Object, ByVal Redval As Long, ByVal Greenval As _
Long, ByVal Blueval As Long, ByVal Direction As Integer)
Dim Step As Integer, Reps As Integer, FillTop As Integer
Dim FillLeft As Integer, FillRight As Integer, FillBottom As Integer
If Direction < 1 Or Direction > 4 Then Direction = 1
FillTop = 0
FillLeft = 0
If Direction < 3 Then
Step = (TheObject.Height / 100)
If Direction = 2 Then FillTop = TheObject.Height - Step
FillBottom = FillTop + Step
FillRight = TheObject.Width
Else
Step = (TheObject.Width / 100)
If Direction = 4 Then FillLeft = TheObject.Width - Step
FillRight = FillLeft + Step
FillBottom = TheObject.Height
End If
For Reps = 1 To 100
If Direction = 2 And Reps = 100 Then FillTop = 0
If Direction = 4 And Reps = 100 Then FillLeft = 0
Redval = Redval - 3
Greenval = Greenval - 3
Blueval = Blueval - 3
If Redval <= 0 Then Redval = 0
If Greenval <= 0 Then Greenval = 0
If Blueval <= 0 Then Blueval = 0
TheObject.Line (FillLeft, FillTop)-(FillRight, FillBottom), RGB(Redval, _
Greenval, Blueval), BF
If Direction < 3 Then
If Direction = 1 Then
FillTop = FillBottom
Else
FillTop = FillTop - Step
End If
FillBottom = FillTop + Step
Else
If Direction = 3 Then
FillLeft = FillRight
Else
FillLeft = FillLeft - Step
End If
FillRight = FillLeft + Step
End If
Next Reps
End Sub

Private Sub Form_Load()
'To make Gradient Picture Box, Replace the 'Me' below with the name of the Picture Box.
'Replace the '200, 100, 300' below with the RGB value of your desirable color. You can
'just try some numbers, till you satisfy.
'Replace the '1' below with the direction of painting. 1 - from top, 2 - from bottom,
'3 - from left, 4 - from right.

Gradient Me, 200, 100, 300, 1
End Sub

Private Sub Form_Resize()
'Put here the same numbers as you put above
Gradient Me, 200, 100, 300, 1
End Sub

Go Back