Results 1 to 21 of 21

Thread: Prevent Mouse from changing caret location in Textbox.

Hybrid View

  1. #1

    Thread Starter
    PowerPoster cafeenman's Avatar
    Join Date
    Mar 2002
    Location
    Florida
    Posts
    2,819

    Re: Prevent Mouse from changing caret location in Textbox.

    Actually now that I think about it (this is air code), this might work.

    **** Edit

    Nope. It mostly works but if I start frantically clicking on the textbox then the caret moves.

    If I behave like a reasonable person then it seems to work ok.

    Not a great solution in other words. But I'm leaving it for your judgement.

    ******

    Code:
    Public Sub SimulateTyping(ByRef Text As String, ByRef Textbox As VB.Textbox, Optional ByRef PauseMS As Long = 150)
    Dim n As Long
    Dim s As String
    dim nStartPos as long
    
    ' Adds delay between characters to simulate typing.
    ' Starts 'typing' wherever the caret is.
    
    If Len(Text) = 0 Then Exit Sub
    
    With Textbox
    
      nStartPos = .Selstart
    
      For n = 1 To Len(Text)
    
        .Selstart = nStartPos + n ' This *might* put the caret back before typing the next thing in the wrong place?
    
        .SelText = Mid$(Text, n, 1)
    
        Sleep RollDie(PauseMS)
    
      Next n
    
    End With
    
    End Sub
    Last edited by cafeenman; Dec 20th, 2024 at 03:25 AM.

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