Highlights
All Snippets
Top 100 Snippets
Librarians
gbCodeLib

By Language
VB6
JavaScript
Perl
HTML
SQL
Java
DOS

GBIC >> Source Code >> Visual Basic >> Snippet

Gradient - apply to form, 2 colors, 4 directions


Sub ColorForm(F As Form, Direction As Long , R1 As Integer , G1 As Integer , B1 As Integer , R2 As Integer , G2 As Integer , B2 As Integer )
   
   F.DrawStyle = vbInsideSolid
   F.DrawMode = vbCopyPen
   F.ScaleMode = vbPixels
'    F.DrawWidth = 2
   F.AutoRedraw = True
   
   
    Dim i As Integer , iHeight As Integer , iWidth As Integer
    Dim R As Integer , G As Integer , B As Integer
   iWidth = F.ScaleWidth
   iHeight = F.ScaleHeight
   
    Select Case Direction
        Case 1
            'bottom to top
            For i = 0 To iHeight
               R = R1 - (R1 - R2) / iHeight * i
               G = G1 - (G1 - G2) / iHeight * i
               B = B1 - (B1 - B2) / iHeight * i
               F.Line (0, i) - (iWidth, i), RGB(R, G, B), B
            Next i
        Case 2
            'top to bottom
            For i = 0 To iHeight
               R = R1 - (R1 - R2) / iHeight * i
               G = G1 - (G1 - G2) / iHeight * i
               B = B1 - (B1 - B2) / iHeight * i
               F.Line (0, iHeight - i) - (iWidth, iHeight - i), RGB(R, G, B), B
            Next i
        Case 3
            'left to right
            For i = 0 To iWidth
               R = R1 - (R1 - R2) / iHeight * i
               G = G1 - (G1 - G2) / iHeight * i
               B = B1 - (B1 - B2) / iHeight * i
               F.Line (i, 0) - (i, iHeight), RGB(R, G, B), B
            Next i
        Case 4
            'right to left
            For i = 0 To iWidth
               R = R1 - (R1 - R2) / iHeight * i
               G = G1 - (G1 - G2) / iHeight * i
               B = B1 - (B1 - B2) / iHeight * i
               F.Line (iWidth - i, 0) - (iWidth - i, iHeight), RGB(R, G, B), B
            Next i
   End Select

End Sub