Results 1 to 5 of 5

Thread: change cursor position

  1. #1

    Thread Starter
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    ok, so I have a button thst I want to use to take the cursor
    in a RichText Box from where ever it is in the box, to the beginning of the test in the box, how could I do that?

  2. #2
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527
    do you mean the mouse cursor or the flashing cursor in the rtb?

    code for setting flashing cursor pos in rtb
    Code:
    Private Sub Text1_GotFocus()
    RTB1.SelStart = 0
    End Sub

  3. #3
    Guest
    Use the RichTextBox's SelStart property and then set focus to it:

    Code:
    RichTextBox1.SelStart = 0
    RichTextBox1.SetFocus

  4. #4
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527
    code to randomize the cursor's position
    Code:
    'in a module
    Declare Function SetCursorPos Lib "user32.dll" (ByVal x As Long, ByVal y As Long) As Long
    
    'wherever
    Dim myX As Integer
    Dim myY As Integer
    Randomize
    myX = Int(600 * Rnd)
    myY = Int(600 * Rnd)
    Debug.Print myX & ":" & myY
    retval = SetCursorPos(myX, myY)

  5. #5
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527
    Originally posted by Matthew Gates
    Use the RichTextBox's SelStart property and then set focus to it:

    Code:
    RichTextBox1.SelStart = 0
    RichTextBox1.SetFocus

    bad luck, beat you by two minutes

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