Results 1 to 8 of 8

Thread: How to pre-select the text in a text box

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    May 2000
    Location
    Wellington NZ
    Posts
    153

    Wink

    I have a text box and i need to know how to select the highlight text in the text box, i am not sure how to do this and would like some help if you could give me any example code i would like to thank you ver much...

    Rohan

  2. #2
    Fanatic Member
    Join Date
    Mar 2000
    Location
    That posh bit of England known as Buckinghamshire
    Posts
    658
    not sure what you mean.

    To highlight text do
    Code:
    'highlights all of the text in the text box
    
    Text1.SelStart = 0
    Text1.SelLength = Len(Text1.Text)

    to get the highlighted text into a variable use.
    Code:
    strText = Mid$(Text1.Text, Text1.SelStart, Text1.SelLength)
    Iain, thats with an i by the way!

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    May 2000
    Location
    Wellington NZ
    Posts
    153

    Angry Cannot get that to work

    The method that you just posted didnt seem to work here is the code that i am using......

    Private Sub lstCourses_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    txtsearch.Text = lstCourses.Text
    txtsearch.SelStart = 0
    txtsearch.SelLength = Len(txtsearch.Text)
    End Sub

  4. #4
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Iain, you can use seltext property instead to get the selected text:
    Code:
    strText = text1.seltext
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  5. #5
    Fanatic Member
    Join Date
    Mar 2000
    Location
    That posh bit of England known as Buckinghamshire
    Posts
    658
    Doh, forgot all about that Kedaman. Silly me.

    Any way, for a text box to be highlighted it must have the focus. So at the end of that sub do.

    "Text1.SetFocus"
    Iain, thats with an i by the way!

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    May 2000
    Location
    Wellington NZ
    Posts
    153

    Working...Thank you guys

    It works .... I didnt set the focus....thank you

  7. #7
    Fanatic Member
    Join Date
    Mar 2000
    Location
    That posh bit of England known as Buckinghamshire
    Posts
    658
    Or set the textboxes "HideSelection" property to false. This will cause the text box to show what is highlighted even when it does not have the focus.
    Iain, thats with an i by the way!

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    May 2000
    Location
    Wellington NZ
    Posts
    153

    Thumbs up Question.....

    That was my next question......thank you guys

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