Results 1 to 18 of 18

Thread: flashing and scrolling

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2003
    Posts
    509

    flashing and scrolling

    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

  2. #2
    Addicted Member
    Join Date
    Apr 2002
    Location
    California
    Posts
    160
    For Flashing:

    VB Code:
    1. Private Sub Textbox_Scroller_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    2.         txtScrollText.Text = "Jason"
    3.         timScroll.Enabled = True
    4. End Sub
    5.  
    6. Private Sub timScroll_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles timScroll.Tick
    7.         If txtScrollText.Visible Then
    8.             txtScrollText.Visible = False
    9.         Else
    10.             txtScrollText.Visible = True
    11.         End If
    12. End Sub
    Jason Moore

    Software Engineer, Database Architect, Web Designer

    (C#,VB/NET,ASP/NET,COLDFUSION,JAVASCRIPT,SQL)

    http://www.gatorstudios.com
    [email protected]

  3. #3
    Addicted Member
    Join Date
    Apr 2002
    Location
    California
    Posts
    160
    Here is an example with a flashing and scrolling textbox.
    Attached Files Attached Files
    Jason Moore

    Software Engineer, Database Architect, Web Designer

    (C#,VB/NET,ASP/NET,COLDFUSION,JAVASCRIPT,SQL)

    http://www.gatorstudios.com
    [email protected]

  4. #4

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2003
    Posts
    509
    Thats kind of what i wanted. Is there a way of just moving the text within the textbox and not the textbox itself?

    I also need to adapt a time limit so it only flashes for 3 seconds

  5. #5
    Addicted Member
    Join Date
    Apr 2002
    Location
    California
    Posts
    160
    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:
    1. dim i as integer = 1  'goes in the global portion of the forms class
    2.  
    3. 'goes in the timScroll_tick event
    4.  
    5. i+= 1                
    6.  
    7. 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

    (C#,VB/NET,ASP/NET,COLDFUSION,JAVASCRIPT,SQL)

    http://www.gatorstudios.com
    [email protected]

  6. #6
    Fanatic Member pax's Avatar
    Join Date
    Mar 2001
    Location
    Denmark
    Posts
    840
    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...

    ...Currently using VS2013...

  7. #7
    Addicted Member
    Join Date
    Apr 2002
    Location
    California
    Posts
    160
    LOL. You caught me. So, so tired. Thanks for catching that brain fart.
    Jason Moore

    Software Engineer, Database Architect, Web Designer

    (C#,VB/NET,ASP/NET,COLDFUSION,JAVASCRIPT,SQL)

    http://www.gatorstudios.com
    [email protected]

  8. #8
    Fanatic Member pax's Avatar
    Join Date
    Mar 2001
    Location
    Denmark
    Posts
    840
    No worries. Kind'a figured (hoped) it was a mistake.

    Sleep Tight.
    I wish I could think of something witty to put in my sig...

    ...Currently using VS2013...

  9. #9

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2003
    Posts
    509
    ok forget the timer bit, im sure i can do that.

    The problem is making the text within the textbox move. Ive tried

    txtScroll.text.left but that comes up with an error.

    it seems simple but i cant work it out-go on help me out

  10. #10
    Addicted Member
    Join Date
    Apr 2002
    Location
    California
    Posts
    160
    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.
    Attached Files Attached Files
    Jason Moore

    Software Engineer, Database Architect, Web Designer

    (C#,VB/NET,ASP/NET,COLDFUSION,JAVASCRIPT,SQL)

    http://www.gatorstudios.com
    [email protected]

  11. #11

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2003
    Posts
    509
    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

    End If

    ' Set the next tick count
    iTick += 1

    End Sub

  12. #12
    Addicted Member
    Join Date
    Apr 2002
    Location
    California
    Posts
    160
    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:
    1. Class MyForm
    2.  
    3. Dim iTick as integer
    4. Dim strText as string
    5. Dim arrText(100) as string  ' set this to the max amount of characters you will need
    6. Dim blnReverse as boolean
    7.  
    8. Sub Page_Load
    9. '
    10. '
    Jason Moore

    Software Engineer, Database Architect, Web Designer

    (C#,VB/NET,ASP/NET,COLDFUSION,JAVASCRIPT,SQL)

    http://www.gatorstudios.com
    [email protected]

  13. #13

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2003
    Posts
    509
    i have set the textbox property maximum value to 62 which is just at the edge of the box.
    I have then set the array value to 16.

    This is the outcome: It scrolls first and then it scrolls again and then it stops.
    How come it stops scrolling? I would

  14. #14

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2003
    Posts
    509
    sorry must of pressed enter.

    I meant to say: i would like for it to keep scrolling untill the program is stopped.

    I am initialising the timer in the form load.

  15. #15
    Addicted Member
    Join Date
    Apr 2002
    Location
    California
    Posts
    160
    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

    (C#,VB/NET,ASP/NET,COLDFUSION,JAVASCRIPT,SQL)

    http://www.gatorstudios.com
    [email protected]

  16. #16

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2003
    Posts
    509
    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.
    Attached Files Attached Files

  17. #17
    Addicted Member
    Join Date
    Apr 2002
    Location
    California
    Posts
    160
    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).
    Attached Files Attached Files
    Jason Moore

    Software Engineer, Database Architect, Web Designer

    (C#,VB/NET,ASP/NET,COLDFUSION,JAVASCRIPT,SQL)

    http://www.gatorstudios.com
    [email protected]

  18. #18

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2003
    Posts
    509
    Thanx for ur help. There is no edge problem. It seems to be working fine. I know what u mean, i got that same problem at the start too.

    But seriously, thanx for the help-much appreciated

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width