Results 1 to 40 of 4199

Thread: CommonControls (Replacement of the MS common controls)

Threaded View

  1. #11

    Thread Starter
    PowerPoster
    Join Date
    Jun 2012
    Posts
    2,728

    Re: CommonControls (Replacement of the MS common controls)

    Quote Originally Posted by Karl77 View Post
    Textbox problem

    In my program I have a routine that selects all text in a textbox when it gets the focus (optional).
    This doesn't work with TextBoxW so very well.

    Code:
    Private Sub TextBoxW1_GotFocus()
    
    With TextBoxW1
    .SelStart = 0
    .SelLength = 999
    End With
    
    End Sub
    The effect is, that the text gets selected from the start to the clicked point.

    The intrinsic textbox doesn't show this behavior.
    The text gets completely selected as intended.
    I did a test with an intrinsic VB TextBox and the TextBoxW:
    Code:
    Private Sub Text1_GotFocus()
    With Text1
    .SelStart = 0
    .SelLength = 999
    End With
    End Sub
    
    Private Sub TextBoxW2_GotFocus()
    With TextBoxW2
    .SelStart = 0
    .SelLength = 999
    End With
    End Sub
    Both do select the whole text at GotFocus but the mouse click changes the length of selection to actual clicked point.
    So in my point behavior is exactly the same.

    EDIT:
    Proper implementation of AutoSelect by OnFocus would be as following:
    Code:
    Private Sub TextBoxW2_GotFocus()
    If GetMouseStateFromMsg() = 0 Then
        With TextBoxW2
        .SelStart = 0
        .SelLength = Len(.Text)
        .Tag = "Focused"
        End With
    End If
    End Sub
    
    Private Sub TextBoxW2_LostFocus()
    TextBoxW2.Tag = vbNullString
    End Sub
    
    Private Sub TextBoxW2_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
    With TextBoxW2
    If .SelLength = 0 And .Tag = vbNullString Then
        .Tag = "Focused"
        .SelStart = 0
        .SelLength = Len(.Text)
    End If
    End With
    End Sub
    EDIT2:
    I could include an "AutoSelectOnFocus" property which would take care of this internally.
    Last edited by Krool; Sep 19th, 2017 at 11:47 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