Results 1 to 4 of 4

Thread: [RESOLVED] Fill a Textbox with a delay!

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 2013
    Posts
    124

    Resolved [RESOLVED] Fill a Textbox with a delay!

    Hi,

    I have a textbox I need to copy and paste some text into it. You know, once you select the textbox and press CTRL+V the textbox gets all the clipboard's contents within a wink of an eye! I don't want that, I want the textbox to get the contents of the clipboard a character by character (with a delay), so once you press CTRL+V you see the characters getting filled into the textbox from right to left one by one until the textbox gets all the clipboard's contents say after 2 seconds (depending on the contents' length). Any ideas? Thanks.

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    24,257

    Re: Fill a Textbox with a delay!

    Here's an extended TextBox...

    Code:
    Public Class TextBoxEx
        Inherits TextBox
    
        Const WM_PASTE As Integer = &H302
    
        Private WithEvents tmr As New Timer With {.Interval = 50}
        Private pastedText As String
        Private charCounter As Integer = 0
    
        Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
            If m.Msg = WM_PASTE Then
                pastedText = Clipboard.GetText
                charCounter = 0
                tmr.Start()
                Return
            End If
            MyBase.WndProc(m)
        End Sub
    
        Private Sub tmr_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles tmr.Tick
            If charCounter < pastedText.Length Then
                MyBase.Text &= pastedText.Substring(charCounter, 1)
                charCounter += 1
            Else
                tmr.Stop()
            End If
        End Sub
    
    End Class

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jan 2013
    Posts
    124

    Re: Fill a Textbox with a delay!

    Quote Originally Posted by .paul. View Post
    Here's an extended TextBox...

    Code:
    Public Class TextBoxEx
        Inherits TextBox
    
        Const WM_PASTE As Integer = &H302
    
        Private WithEvents tmr As New Timer With {.Interval = 50}
        Private pastedText As String
        Private charCounter As Integer = 0
    
        Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
            If m.Msg = WM_PASTE Then
                pastedText = Clipboard.GetText
                charCounter = 0
                tmr.Start()
                Return
            End If
            MyBase.WndProc(m)
        End Sub
    
        Private Sub tmr_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles tmr.Tick
            If charCounter < pastedText.Length Then
                MyBase.Text &= pastedText.Substring(charCounter, 1)
                charCounter += 1
            Else
                tmr.Stop()
            End If
        End Sub
    
    End Class
    An idea and a code that puts it into practice? This is more than what I expected!
    I have just tested it and it works exactly as I wanted.
    Thank you very very much!

  4. #4
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    24,257

    Re: [RESOLVED] Fill a Textbox with a delay!


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