Make your own free website on Tripod.com
Draw 3D Gradient Text On Form

Preparations

Add 2 Command Buttons to your form.
Press the first to draw the text, and the second to erase it.

Form Code

Private Sub Command1_Click()
' The first parameter ("VBTown http://cuinl.tripod.com") is the text you want to draw.
' The second parameter (30) is the font size, the third (8) is the text width,
' The forth ("MS Sans Serif"), is the font type, the 5th and 6th (20, 20) are
' the X and Y coordinates where the text will be displayed,
' the next 3 parameters (0,0,0) are the RGB value of the first color, and
' the last 3 parameters (250,0,0) are the RGB value of the second color.
' the text color will be gradient from the first color to the second color
 
' you can change the last 6 parameter to change the text color

    Draw3d "VBTown http://cuinl.tripod.com", 30, 8, "MS Sans Serif", _
                      20, 20, 0, 0, 0, 250, 0, 0
End Sub


Private Sub Command2_Click()
' all the parameters must be the same as the first 6 parameters where you called
' the Draw3d function to draw the text

    Delete3d "VBTown http://cuinl.tripod.com", 30, 8, "MS Sans Serif", 20, 20
End Sub

Private Sub Draw3d(Text As String, FontSize, TextWidth, FontType, _
                        X, Y, FromR, FromG, FromB, ToR, ToG, ToB)
    Me.AutoRedraw = True
    Me.FontSize = FontSize
    Me.Font = FontType
    Me.ScaleMode = 3
   
    Dim i As Integer
  
    Dim FactorR, FactorG, FactorB As Integer
    FactorR = (ToR - FromR) / TextWidth
    FactorG = (ToG - FromG) / TextWidth
    FactorB = (ToB - FromB) / TextWidth
   
    For i = 0 To TextWidth
        CurrentX = i + X
        CurrentY = i + Y
        ForeColor = RGB(FromR, FromG, FromB)
        FromR = FromR + FactorR
        FromG = FromG + FactorG
        FromB = FromB + FactorB
        Me.Print Text
    Next
   
End Sub

Private Sub Delete3d(Text As String, FontSize, TextWidth, FontType, X, Y)
  
    Me.AutoRedraw = True
    Me.FontSize = FontSize
    Me.Font = FontType
    Me.ScaleMode = 3
   
    Dim i As Integer
  
    For i = 0 To TextWidth
        CurrentX = i + X
        CurrentY = i + Y
        ForeColor = Me.BackColor
        Me.Print Text
    Next
End Sub

Go Back