|
-
Sep 11th, 2008, 01:47 PM
#1
Thread Starter
Addicted Member
Text fader (2008)
Hello,
Could anyone provide me with some help or a snippet of code that will enable me to fade text from one colour to another in a rich textbox. I have tried searching the forum but can't seem to find anything relevant.
Regards,
Dan.
-
Sep 11th, 2008, 05:28 PM
#2
Re: Text fader (2008)
try this. i found it on the internet + modified it. it fades the rtb forecolor from color1 to color2
vb Code:
Public Class Form1
Dim mR As Integer
Dim mStepR As Integer
Dim mG As Integer
Dim mStepG As Integer
Dim mB As Integer
Dim mStepB As Integer
Dim mStatus As Integer ' 0 -> Stopped 1-> Fading
Const kSteps As Integer = 10 ' Number of colors between
Dim mContSteps As Integer
' Different States
Const kStatusStopped As Integer = 0
Const kStatusFading As Integer = 1
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
InitFade(Color.Red, Color.Blue)
End Sub
Sub InitFade(ByVal color1 As Color, ByVal color2 As Color)
Dim wRAct As Integer = color1.R
Dim wGAct As Integer = color1.G
Dim wBAct As Integer = color1.B
Dim wRFin As Integer = color2.R
Dim wGFin As Integer = color2.G
Dim wBFin As Integer = color2.B
' Calculate intermediate steps between each of the components
mStepR = CInt((wRAct - wRFin) / kSteps)
mStepG = CInt((wGAct - wGFin) / kSteps)
mStepB = CInt((wBAct - wBFin) / kSteps)
' Initializes Module variables
mR = wRAct
mG = wGAct
mB = wBAct
' Init # of Steps
mContSteps = 0
' Indicates Timer Event to process fade effect
mStatus = kStatusFading
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
If mStatus = kStatusFading Then
mContSteps += 1
If mContSteps = kSteps Then
mStatus = kStatusStopped
Else
If mR - mStepR > 0 Then mR -= mStepR Else mR = 0
If mG - mStepG > 0 Then mG -= mStepG Else mG = 0
If mB - mStepB > 0 Then mB -= mStepB Else mB = 0
RichTextBox1.ForeColor = Color.FromArgb(mR, mG, mB)
Application.DoEvents()
End If
End If
End Sub
End Class
edit: the timer interval is 100ms.
if you want to fade the selected text, it'd be slightly more difficult because the text would be hilighted + you wouldn't see the effects
Last edited by .paul.; Sep 11th, 2008 at 06:18 PM.
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Sep 12th, 2008, 12:01 PM
#3
Thread Starter
Addicted Member
Re: Text fader (2008)
Thanks for the help, That is a great effect but not exactly what I was looking for.
I want the fade to be static and fade from left to right.
Any other ideas,
Regards,
Dan.
-
Sep 12th, 2008, 12:11 PM
#4
Re: Text fader (2008)
in a richtextbox you'll only be able to fade by character. that is 1 character can only be 1 color
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Sep 12th, 2008, 12:15 PM
#5
Thread Starter
Addicted Member
Re: Text fader (2008)
That's fine as long as the next character is almost the same colour as the one before it and gives the effect it is fading throughout the text.
-
Sep 12th, 2008, 12:58 PM
#6
Re: Text fader (2008)
try this
vb Code:
Public Class Form1
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
InitFade(Color.Red, Color.Blue)
End Sub
Sub InitFade(ByVal color1 As Color, ByVal color2 As Color)
Dim steps As Integer = RichTextBox1.Text.Length ' Number of colors between
Dim wRStart As Integer = color1.R
Dim wGStart As Integer = color1.G
Dim wBStart As Integer = color1.B
Dim wRFin As Integer = color2.R
Dim wGFin As Integer = color2.G
Dim wBFin As Integer = color2.B
' Calculate intermediate steps between each of the components
Dim mStepR As Integer = CInt((wRStart - wRFin) / steps)
Dim mStepG As Integer = CInt((wGStart - wGFin) / steps)
Dim mStepB As Integer = CInt((wBStart - wBFin) / steps)
' Initializes Module variables
Dim mR As Integer = wRStart
Dim mG As Integer = wGStart
Dim mB As Integer = wBStart
For x As Integer = 1 To steps
RichTextBox1.SelectionStart = x - 1
RichTextBox1.SelectionLength = 1
RichTextBox1.SelectionColor = Color.FromArgb(mR, mG, mB)
Application.DoEvents()
If mR - mStepR > 0 Then mR -= mStepR Else mR = 0
If mG - mStepG > 0 Then mG -= mStepG Else mG = 0
If mB - mStepB > 0 Then mB -= mStepB Else mB = 0
Next
End Sub
End Class
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Sep 15th, 2008, 03:36 PM
#7
Thread Starter
Addicted Member
Re: Text fader (2008)
That is absolutely perfect!! Thanks a lot!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|