Private Sub mnDraw_Click()
Dim fColor As Integer
Dim arrColors() As Long
Dim steps As Variant
Dim color1 As Long
Dim color2 As Long
Dim posY As Long
'Get color choices from user
With CommonDialog1
.Flags = cdlCCRGBInit
.CancelError = True
On Error Resume Next
.ShowColor
If (Err.Number <> 0) Then
Exit Sub
End If
On Error GoTo 0
color1 = .color
On Error Resume Next
.ShowColor
If (Err.Number <> 0) Then
Exit Sub
End If
On Error GoTo 0
color2 = .color
End With
'Get amount of steps from user
steps = InputBox("Number of steps:", , 32)
If (steps = "") Then
Exit Sub
End If
steps = CLng(steps)
'Calculate gradient; display error message if applicable
If Not (CalculateGradient(color1, color2, steps, arrColors)) Then
MsgBox "An error occured while calculating the gradient!", vbExclamation
Exit Sub
End If
'Get the form ready to paint horizontal lines.
'The easiest way to do it is to use a user scalemode.
Me.ScaleHeight = steps
'Set starting position
posY = Me.ScaleTop
'Now draw boxes
For fColor = LBound(arrColors) To UBound(arrColors)
Me.Line (Me.ScaleLeft, posY)-(Me.ScaleWidth + Me.ScaleLeft, posY + 1), arrColors(fColor), BF
posY = posY + 1
Next fColor
End Sub
You could alter this to make the effect vertical, or starting from the center of the form, or alter the CalculateGradient function to introduce a weight factor to increase the gradient exponencially, or quadratic, or whatever... you name it!
Comments