Dim colVal As Long
' Variable to contain our rgb color value Dim counter As Integer ' Counter to be used to increment/decrement rgb value Dim fIn As Boolean ' Boolean, true/false variable to determine if we are fading in or fading out. ' *** Update *** Dim curMsg As Integer ' Determines which message from the MsgArray to display Dim MsgArray(1 To 9) As String ' New variable Array to allow us to display multiple messages Private Sub Command1_Click() ' Shutdown all components and end the program Timer1.Enabled = False Unload Form1 End End Sub Private Sub Form_Load() ' Setup our messages MsgArray(1) = "Stormdev Software" MsgArray(2) = "Fading Text Demo" MsgArray(3) = "Updated" MsgArray(4) = "Now Allows" MsgArray(5) = "Multiple Messages" ' Use a blank entry for a greater pause before the next message ! MsgArray(6) = "" MsgArray(7) = "Votes Appreciated" MsgArray(8) = "Comments Always Welcome" MsgArray(9) = "stormdev@golden.net" ' Set the current message curMsg = 1 ' Set our counter to zero counter = 0 ' This is our boolean (true/false) variable which will be used ' to determin if we are fading the text in or out. To start we ' set it to true so our text will fade in first. fIn = True ' Show the form Me.Show End Sub Private Sub Timer1_Timer() ' This is the timer that controls our fading in and out, if you ' increase the timers interval property, the fades will take longer, ' you can also alter the fade speed by increasing or decreasing the ' the value that is added to counter in the lines below. ' ' Check and see if we are fading the text in, fIn=true. If fIn = True Then ' If we are fading in then begin the fade routine. ' Check if our counter variable is less than or equal to our goal color, ' I used 170 because that is the rgb value for the red component that ' I wanted the color fade to stop at, but you can use any rgb value and ' the red green or blue components. ' If counter <= 200 Then ' Store our rgb color value into the colVal variable ' Notice the counter variable as the red parameter in the rgb call, the zeros ' for the green and blue components will yield black, you can try putting the ' counter variable in different components and changing component values to get ' the color you desire. colVal = RGB(counter, 0, 0) ' Set the forecolor of our picturebox to the new color Picture1.ForeColor = colVal ' Increment our counter variable, a higher + value will increase fade speed ' while a lower value will slow the fade down and make it more smooth. counter = counter + 5 Else ' If we have reached our final color then set the fIn variable to false ' because we just faded the text in we need it false to fade out next. fIn = False ' Reset the counter counter = 0 End If Else ' If fIn was false that means we are fading out now ' Basically the same code as above, so I won't comment heavily. If counter <= 200 Then colVal = RGB(200 - counter, 0, 0) Picture1.ForeColor = colVal counter = counter + 5 Else fIn = True counter = 0 ' Increment our Message Pointer curMsg = curMsg + 1 End If End If ' Check if the curMsg is at the last ("Upper Boundary"UBound) position of our Array. If curMsg <= UBound(MsgArray) Then ' Print the current message SetTextPosition Picture1.Print MsgArray(curMsg) Else ' Reset our message pointer to the first message to loop through the MsgArray curMsg = 1 End If End Sub Private Sub SetTextPosition() ' Set our current x and y coordinates for writing to the picturebox. ' This line sets the CurrentX property based on the size of the msg ' and centers that line in the textbox horizontally. Picture1.CurrentX = (Picture1.ScaleWidth - Picture1.TextWidth(MsgArray(curMsg))) \ 2 ' You could also use the above routine to center the text vertically, by replacing ' the .ScaleWidth with .ScaleHeight and .TextWidth with .TextHeight, for the CurrentY ' Co-ordinate. ' ie: Picture1.CurrentY = (Picture1.ScaleHeight - Picture1.TextHeight(MsgArray(curMsg))) \ 2 ' ' For Now I will just hard code it as 1 Picture1.CurrentY = 1 End Sub Dim colVal As Long ' Variable to contain our rgb color value Dim counter As Integer ' Counter to be used to increment/decrement rgb value Dim fIn As Boolean ' Boolean, true/false variable to determine if we are fading in or fading out. ' *** Update *** Dim curMsg As Integer ' Determines which message from the MsgArray to display Dim MsgArray(1 To 9) As String ' New variable Array to allow us to display multiple messages Private Sub Command1_Click() ' Shutdown all components and end the program Timer1.Enabled = False Unload Form1 End End Sub Private Sub Form_Load() ' Setup our messages MsgArray(1) = "Stormdev Software" MsgArray(2) = "Fading Text Demo" MsgArray(3) = "Updated" MsgArray(4) = "Now Allows" MsgArray(5) = "Multiple Messages" ' Use a blank entry for a greater pause before the next message ! MsgArray(6) = "" MsgArray(7) = "Votes Appreciated" MsgArray(8) = "Comments Always Welcome" MsgArray(9) = "stormdev@golden.net" ' Set the current message curMsg = 1 ' Set our counter to zero counter = 0 ' This is our boolean (true/false) variable which will be used ' to determin if we are fading the text in or out. To start we ' set it to true so our text will fade in first. fIn = True ' Show the form Me.Show End Sub Private Sub Timer1_Timer() ' This is the timer that controls our fading in and out, if you ' increase the timers interval property, the fades will take longer, ' you can also alter the fade speed by increasing or decreasing the ' the value that is added to counter in the lines below. ' ' Check and see if we are fading the text in, fIn=true. If fIn = True Then ' If we are fading in then begin the fade routine. ' Check if our counter variable is less than or equal to our goal color, ' I used 170 because that is the rgb value for the red component that ' I wanted the color fade to stop at, but you can use any rgb value and ' the red green or blue components. ' If counter <= 200 Then ' Store our rgb color value into the colVal variable ' Notice the counter variable as the red parameter in the rgb call, the zeros ' for the green and blue components will yield black, you can try putting the ' counter variable in different components and changing component values to get ' the color you desire. colVal = RGB(counter, 0, 0) ' Set the forecolor of our picturebox to the new color Picture1.ForeColor = colVal ' Increment our counter variable, a higher + value will increase fade speed ' while a lower value will slow the fade down and make it more smooth. counter = counter + 5 Else ' If we have reached our final color then set the fIn variable to false ' because we just faded the text in we need it false to fade out next. fIn = False ' Reset the counter counter = 0 End If Else ' If fIn was false that means we are fading out now ' Basically the same code as above, so I won't comment heavily. If counter <= 200 Then colVal = RGB(200 - counter, 0, 0) Picture1.ForeColor = colVal counter = counter + 5 Else fIn = True counter = 0 ' Increment our Message Pointer curMsg = curMsg + 1 End If End If ' Check if the curMsg is at the last ("Upper Boundary"UBound) position of our Array. If curMsg <= UBound(MsgArray) Then ' Print the current message SetTextPosition Picture1.Print MsgArray(curMsg) Else ' Reset our message pointer to the first message to loop through the MsgArray curMsg = 1 End If End Sub Private Sub SetTextPosition() ' Set our current x and y coordinates for writing to the picturebox. ' This line sets the CurrentX property based on the size of the msg ' and centers that line in the textbox horizontally. Picture1.CurrentX = (Picture1.ScaleWidth - Picture1.TextWidth(MsgArray(curMsg))) \ 2 ' You could also use the above routine to center the text vertically, by replacing ' the .ScaleWidth with .ScaleHeight and .TextWidth with .TextHeight, for the CurrentY ' Co-ordinate. ' ie: Picture1.CurrentY = (Picture1.ScaleHeight - Picture1.TextHeight(MsgArray(curMsg))) \ 2 ' ' For Now I will just hard code it as 1 Picture1.CurrentY = 1 End Sub |