Results 1 to 12 of 12

Thread: Text Box manipulation

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Dec 2001
    Location
    California
    Posts
    25

    Text Box manipulation

    I want to select all charaters previously typed into a text box (as if you double click inside the box) so the next key stroke overwirtes what was there.

    How?
    While you are at it, how to make sucessive presses of the left arrow key erase the last character in a text box and leave the cursor there.

  2. #2
    -= B u g S l a y e r =- peet's Avatar
    Join Date
    Aug 2000
    Posts
    9,629
    VB Code:
    1. Private Sub Command1_Click()
    2.     Text1.SetFocus
    3.     Text1.SelStart = 0
    4.     Text1.SelLength = Len(Text1.Text)
    5. End Sub

  3. #3
    -= B u g S l a y e r =- peet's Avatar
    Join Date
    Aug 2000
    Posts
    9,629
    VB Code:
    1. Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer)
    2.     If KeyCode = vbKeyLeft Then
    3.         KeyCode = 0
    4.         SendKeys "{BACKSPACE}"
    5.     End If
    6. End Sub

  4. #4
    Frenzied Member MrGTI's Avatar
    Join Date
    Oct 2000
    Location
    Ontario, Canada
    Posts
    1,277

    Thumbs up

    I have made a DLL that does all that for you. You can grab it and use it for free. It does tons more as well.

    CommonCode DLL
    ~Peter


  5. #5
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527
    but he only wants to do 2 things, which he has achieved.

    why add a dll if you can do it in 5 lines of code?

  6. #6
    Frenzied Member MrGTI's Avatar
    Join Date
    Oct 2000
    Location
    Ontario, Canada
    Posts
    1,277
    Excellent point.

    The answer is he could probably find many of the other features of the DLL useful. And since it is a free DLL, and he is more than welcome to distribute it freely without royalty or credit to me, the chance that it will become a useful tool in building his app are greater.

    Did you look at the list of things it does? The name CommonCode says it all.

    (and yes, i did generate some of the code in there with the help you all the great folks on this forum. i'm just happy i can share it with you all)
    ~Peter


  7. #7

    Thread Starter
    Junior Member
    Join Date
    Dec 2001
    Location
    California
    Posts
    25
    I just ended a class in Visual Basic, just scratched the surface of what can be done.

    Concerning the DLL, if I only knew what a dll is and how to use it...

    I suppose in time I will learn.

  8. #8
    Frenzied Member MrGTI's Avatar
    Join Date
    Oct 2000
    Location
    Ontario, Canada
    Posts
    1,277

    Talking

    Hahhaa.

    Don't worry KMMATH, i provide a complete sample application with the DLL so you can easily just look at the code.

    Failing that, you can always ask me or the folks here in this forum.
    ~Peter


  9. #9
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527
    hmmm

    not bad

    is it "open" soruce?

    i wouldn't mind seeing how u handle the restriction of entry into a text box....

    like, how you apply it to a textbox

  10. #10
    Frenzied Member MrGTI's Avatar
    Join Date
    Oct 2000
    Location
    Ontario, Canada
    Posts
    1,277

    Wink

    No. Sorry da_silvy. It's not an open source DLL.

    BUT - none of the code in there is top secret. It's all simple code i have learned over the last few years, as well as a few special functions that i had help with from people here in this forum.

    Like i said .... it's a free DLL. There is no charge for it, and no need to give me credit if you use it in a project. I just got sick of always adding the same code into every new project, so i decided to make it simplier by packaging all those functions into a single file.
    ~Peter


  11. #11
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527
    hehehe

    i didn't ask if it was open source, i just asked if i could see it

    That's fine. i just wanted to see how u would set the format of the textbox from an external dll...

  12. #12
    Frenzied Member MrGTI's Avatar
    Join Date
    Oct 2000
    Location
    Ontario, Canada
    Posts
    1,277

    Thumbs up

    Well, .... in YOUR program, you would have this code:
    VB Code:
    1. Private Sub txtHighlight_GotFocus()
    2.     Call CC.HighlightEntireSelection(txtHighlight)
    3. End Sub
    That is done quite simply in my DLL by doing this:
    VB Code:
    1. Public Sub HighlightEntireSelection(ByRef objTextArea As Object)
    2. 'Highlights the entire selection
    3.     On Error Resume Next
    4.     If TypeOf objTextArea Is ComboBox Or TypeOf objTextArea Is TextBox Then
    5.         objTextArea.SelStart = 0
    6.         objTextArea.SelLength = Len(objTextArea.Text)
    7.     End If
    8. End Sub
    See. Nothing special. Just code that well all understand. I just packaged it all up into a really easy to use DLL. It's made all my projects smaller.
    ~Peter


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