Results 1 to 5 of 5

Thread: Select Text TextBox

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Oct 2006
    Location
    Spain
    Posts
    97

    Select Text TextBox

    Hello,

    Is possible when thorn with stylus (Pocket PC) upon a TextBox selects the text? I have tried with the GotFocus Event and SelectAll method but does not work. Also I found a code in this forum but it does not work either

    Some solution?

    VB Code:
    1. Private Sub TextBox1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.Click
    2.         Dim txtHold As TextBox = CType(sender, TextBox)
    3.  
    4.         For intBeg As Int32 = (txtHold.SelectionStart * -1) To 0
    5.             If Math.Abs(intBeg) = txtHold.Text.Length Then
    6.                 'Beyond the length of the string, nothing selected.
    7.             ElseIf txtHold.Text.Substring(Math.Abs(intBeg), 1) = " " Then
    8.                 txtHold.SelectionStart = Math.Abs(intBeg) + 1
    9.                 txtHold.SelectionLength = selLen(txtHold, intBeg)
    10.                 Exit For
    11.             ElseIf intBeg = 0 Then
    12.                 txtHold.SelectionStart = intBeg
    13.                 txtHold.SelectionLength = selLen(txtHold, intBeg)
    14.             End If
    15.         Next intBeg
    16.     End Sub
    17.     Private Function selLen(ByRef txtHold As TextBox, ByVal intBeg As Int32) As Int32
    18.         For intEnd As Int32 = txtHold.SelectionStart + 1 To txtHold.Text.Length
    19.             If txtHold.Text.Substring(intEnd, 1) = " " Then
    20.                 Return (intEnd - txtHold.SelectionStart)
    21.                 Exit For
    22.             ElseIf intEnd = txtHold.Text.Length - 1 Then
    23.                 Return (intEnd - txtHold.SelectionStart + 1)
    24.                 Exit For
    25.             End If
    26.         Next
    27.     End Function

    Thank you

  2. #2
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,106

    Re: Select Text TextBox

    I'm not sure what the first sentence means. I assume 'thorn' is a typo, but I can't figure out what word it should be. Therefore, I can't quite figure out what the question is? A double tap would select all the text, are you looking for that event?
    My usual boring signature: Nothing

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Oct 2006
    Location
    Spain
    Posts
    97

    Re: Select Text TextBox

    Hello,

    My English is not perfect. When I strike once with stylus, I want that it selects the text automatically.

    Thank you

  4. #4
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,106

    Re: Select Text TextBox

    Ok, that's fine. The code posted looks like it is intended to select all text from the point of click to the end of the text. It sounds like you want the single tap (click) to act the same way that the double tap works.

    I'd have to test this, which I can't do today, but it looks like you'd want to modify the above code in a fashion like this:

    VB Code:
    1. Private Sub TextBox1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.Click
    2.  Dim txtHold As TextBox = CType(sender, TextBox)
    3.  
    4.  txtHold.SelectionStart=0
    5.  txtHold.SelectionLength=txthold.text.length
    6.  
    7. End Sub
    My usual boring signature: Nothing

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Oct 2006
    Location
    Spain
    Posts
    97

    Re: Select Text TextBox

    This code does not work, does not appear the selected text but the text works double click without events selecting

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