I am trying to make text within a textbox flash and scroll from one side to the other and to re-appear on the other side.
Either one of these will do, both would be fantastic.
This is what i have so far, but it only flashes once, and it doesnt scroll, so i have a feeling im off the track.
I just need to do this for 3 seconds. After this the textbox should be cleared.
Can anyone help me?
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Static seconds As Integer
seconds = 0
seconds = seconds + 1000
If seconds <> 3000 Then
TextBox1.Visible = False
TextBox1.Visible = True
ElseIf seconds = 3000 Then
Timer1.Stop()
TextBox1.Visible = True
TextBox1.Text = ""
End If
End Sub
Private Sub Button12_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button12.Click
If TextBox1.Text = "7265" Then
TextBox1.PasswordChar = ""
TextBox1.Text = "Pin Number Accepted"
Else
TextBox1.PasswordChar = ""
TextBox1.Text = "Incorrect Pin"
Timer1.Enabled = True
End If
End Sub
I also need to adapt a time limit so it only flashes for 3 seconds
Just remember that the timer interval is in milliseconds, so if you set the timer interval for the flashbox to 60 then that = 1 sec. So now you can add a variable to the declariation of the class to count how many ticks have been processed:
This assumes you have set the timer interval to 60 so the increments equal to 1 sec. Else youll need to do the math like if you set the timer interval to 120 then each tick is 2 seconds
VB Code:
dim i as integer = 1 'goes in the global portion of the forms class
'goes in the timScroll_tick event
i+= 1
if i = 3 then timScroll.stop() 'or stop at 3 seconds if the timer interval is 60
Is there a way of just moving the text within the textbox and not the textbox itself?
Im going to let you play with that one for a while, just remember use the seperate timer control to manipulate the text box. If you really are having a hard time with it I might help you some more.
Jason Moore
Software Engineer, Database Architect, Web Designer
Just remember that the timer interval is in milliseconds, so if you set the timer interval for the flashbox to 60 then that = 1 sec. So now you can add a variable to the declariation of the class to count how many ticks have been processed:
This assumes you have set the timer interval to 60 so the increments equal to 1 sec. Else youll need to do the math like if you set the timer interval to 120 then each tick is 2 seconds
uhm...Not true. The interval is in milliseconds allright, but theres 1000 ms to the second, which means that 1 sec = 1000, so 120 is not 2 secs. but only 0.12 sec.
I wish I could think of something witty to put in my sig...
Attached is a sample form with scrolling textbox text, flashing color text and the flashing textbox. This should help you out with the many different things you can do with controls as well.
Jason Moore
Software Engineer, Database Architect, Web Designer
Almost there. I got the text too scroll-thanx for that. The problem i found it only scrolls once and doesnt repeat scrolling. Heres your code from your sample program. What can i add to it to make it repeat scrolling?
Private Sub InitializeDoScroll()
' This trims out any spaces, and sets a variable to keep what text was entered in its
' original form.
strText = Trim(txtEntered.Text)
' Reset the text in the box to the original string
txtEntered.Text = strText
' Initalize the array with each character in the text box
arrText = txtEntered.Text.ToCharArray
' Reverse the array, because when the text scrolls in we want to add characters at the
' end of the string first.
Array.Reverse(arrText)
' Clear the textbox to get ready to scroll it in and out.
txtEntered.Clear()
End Sub
Private Sub DoTextScroll()
' Make sure you read the InitializeTextScroll Function to see what object are
' initialized as
'
'Temp string for adding chars to the textbox
Dim strAdd As String
'if not already in reverse mode and the string is at the end of the box then start reverse mode
If blnReverse = False And (iTick + txtEntered.Text.Length) = txtEntered.MaxLength Then
blnReverse = True
're-initialize the tick count
iTick = 0
End If
' Reverse mode is when the last character of the string is at the MaxLength of the
' TextBox. It will start deleting characters of the end and then puts space at the
' start of the string to simulate the string sliding out.
If blnReverse Then ' if reverse is true start sliding out
' Check if tick count is lower than the length of our char array. This ensures
' that it only deletes the characters of the original string.
If iTick < arrText.Length Then
' Delete 1 character from the end of the string and add a space to the start
txtEntered.Text = " " + txtEntered.Text.Remove(txtEntered.Text.Length - 1, 1)
Else
' If there are no more characters left of the original string then clear the
' text.
txtEntered.Text = ""
' Initialize the tick count to -1 because we need it to be 0 when it loops back
iTick = -1
' Take the loop out of reverse mode
blnReverse = False
End If
Else ' We not in reverse or sliding out mode then we need to slide the text in.
' If the tick count is still lower than the number of character in the original string.
If iTick < arrText.Length Then
' Set the string to be added to the start of the textbox to the next character
' in the char array.
' This simulates the string sliding in.
strAdd = CType(arrText(iTick), String)
Else
' If the array has no more charcters then set the string to add to a space
' This simulates the string sliding across the textbox
strAdd = " "
End If
' Add the character we set above to the start of the textbox along with the text
' already in the box
txtEntered.Text = strAdd & txtEntered.Text
It should work, it does when I use it. One thing I did do was use the MaxLength of the textbox to determine the edge of the box. There is a better way to do that and I dont remember how (didnt really feel like trying to figure that out right now) but it requires you to do calculations to determine the number of windows pixels to the width of a character and u will be able to use the actual size of the textbox rather than the MaxLength (which can go beyond the size of the textbox). At any rate you just need to adjust the MaxLength to match the size of your Textbox which unfortunaley limits the number of characters that can be entered to only the size of the box.
The above explains the path to take if you want to disable that limitation. The scroll should repeat, as i said it does on my screen.
Does it work on the sample form I gave you? If so then make sure you adjust the MaxLength of the textbox you are using and if you use say a button or something else to start the timer then make sure you reset the iTick counter to 0 before starting the timer. This ensures that if you stopped the timer for some reason in the middle of the scroll that the tick count always gets set back to 0. Unfortunalety timers dont come with ON_TIMER_STOP or START events.
The other thing is make sure that the variable iTick, strText, arrText and blnReverse are declared in the Class scope not in the function, sub or event scope.
VB Code:
Class MyForm
Dim iTick as integer
Dim strText as string
Dim arrText(100) as string ' set this to the max amount of characters you will need
Dim blnReverse as boolean
Sub Page_Load
'
'
Jason Moore
Software Engineer, Database Architect, Web Designer
Hmm.. I dont get that problem here. Here is what you can do:
Set a breakpoint at "If iTick < arrText.Length Then" in the function and when it breaks step through and watch the autos. Then you can determine when the scroll stops.
If you want past the entire form here or zip it up and send it to me. Please use the vbcode blocks when pasting code, its easier to read.
Jason Moore
Software Engineer, Database Architect, Web Designer
i did what u said, but to be honest, im not sure what im looking at. So heres my program. I zipped the whole thing.
Thanx if u can work it out. There are two forms, but its in the second form that everything is happening. Its already set to load this form. The textbox that has entry to tower a is what i want to scroll. Please note that this program has no exit button-this is due to the type of program it is.
I fixed it, for some reason there was a part of the code that was qouted out, im not sure if i did that or what, weird though. Anyway it was just 1 line.
Also I added some more maxvalue to the box to let it slide better, you will see.
Im am however concerend about the fact that at the edge it deletes the characters correctly but it starts deleting away from the edge. I am working on resolving that. Ill send you an update when done.
It should scroll correctly now(beside the edge problem).
Jason Moore
Software Engineer, Database Architect, Web Designer