textbox animation

zack

Well-known member
Joined
Jun 9, 2005
Messages
65
Programming Experience
Beginner
hi sir,

do you have any ideas how to make the label text change colour when the text in the label itself changes?
Thx
 
are you trying to make a marquee ... ?
If it's so you don't need a label ... it's much better if you use Graphics object for the purpose.

Cheers ;)

btw, of course you can change the text forecolor

VB.NET:
Private [/color][/size][size=2][color=#0000ff]Sub[/color][/size][size=2] Label1_TextChanged([/size][size=2][color=#0000ff]ByVal[/color][/size][size=2] sender [/size][size=2][color=#0000ff]As [/color][/size][size=2][color=#0000ff]Object[/color][/size][size=2], [/size][size=2][color=#0000ff]ByVal[/color][/size][size=2] e [/size][size=2][color=#0000ff]As[/color][/size][size=2] System.EventArgs) [/size][size=2][color=#0000ff]Handles[/color][/size][size=2] Label1.TextChanged
 
[/size][size=2][color=#0000ff]Me[/color][/size][size=2].Label1.ForeColor = Color.Aqua
 
[/size][size=2][color=#0000ff]End [/color][/size][size=2][color=#0000ff]Sub

 
Hi I think it is a marquee Im' trying to get. Because it ain't as easy as just changing a forecolour.

The label i'm doing actually respond to a .peek reader. thus the text in the label actually changes as the file itself is being read.
So I need something that actually changes the colour of the text in label as the text in the label changes.

If a marquee can actually do this job... Can you provide me with an example or codes?
Thanks alot!
 
You say that the colour will change as the text changes, but you don't say how. Are you just wanting to change to some different colour as each character is added or is there some other specific formula you want to use. Kulrom's code does exactly what you asked for in your first post. If the situation is more complex than that then we need more information to make an informed decision on what advice to provide.
 
This is part of my codes:

While Reader1.Peek() <> -1
Me.BackColor = System.Drawing.Color.Salmon
Dim Info As String
Dim lat As String
Dim lon As String
lblcoord.Text = "Car Location: " & Reader1.ReadLine()
Info = lblcoord.Text
lon = Info.Substring(14, 10)
lat = Info.Substring(27, 8)
dlon = System.Convert.ToDouble(lon)
dlat = System.Convert.ToDouble(lat)

The text in the label changes accordingly as it reads the text file in another location. What I'm trying to acheive is that as the text changes, the colour of the text must also change.
 
Can you please explain exactly what you mean? Do you want the text to change to one colour when it starts reading the file and then change back when the file is finished? Do you want to change the text to a different colour each time a line is read? If so, how are these colours to be chosen? Will it be random or do you already have the desired colours defined? We are not mind readers.
 
I want to change the text to a different colour each time a line is read. I would like the colours to be defined.

Sorry for the inconvenience caused...
 
Now that we know the requirements, the only thing that remains is to determine whether you want to change the text colour of a Label, a TextBox or the whole form. The thread title says "textbox", your first post says "label" but your last post is changing the BackColor of the entir form. I'll assume that it is the label and suggest code like this:
VB.NET:
Dim colours As Color() = New Color() {Color.Red, Color.Green, Color.Blue}
Dim colourIndex As Integer = -1
Dim myReader As New IO.StreamReader("file path here")

While myReader.Peek() <> -1
	If colourIndex = colours.Length - 1
		colourIndex = 0
	Else
		colourIndex += 1
	End If

	Me.Label1.ForeColor = colours(colourIndex)
	Me.Label1.Text = myReader.ReadLine()
End While

myReader.Close()
 
Hi, it appears that this line of code brings out an error of: Overload resolution failed because no 'New' is accessible.

Dim colours As Color() = New Color() {Color.Red, Color.Green, Color.Blue}

Even if i change the code to:
Dim colours As Color() = System.Drawing.Color(Color.Red, Color.Green, Color.Blue)

This error occurs: 'Color' is a type in 'Drawing' and cannot be used as an expression.

 
I have no such issue so you must have done something wrong. Make sure you have the paraentheses and braces in all the correct places. Note that you are declaring a new Color array and assigning to it an array of Color objects, so you need parentheses (round brackets) after Color in each case and braces (curly brackets) around the literal array.
VB.NET:
 Dim colours As Color[color=Red]()[/color] = New Color[color=Red]()[/color] [color=SeaGreen]{[/color]Color.Red, Color.Green, Color.Blue[color=SeaGreen]}[/color]
 
Back
Top