Results 1 to 15 of 15

Thread: selecting text in the text box

  1. #1

    Thread Starter
    Lively Member sameer spitfire's Avatar
    Join Date
    Nov 2001
    Location
    India
    Posts
    120

    selecting text in the text box

    I have a form with text boxs on it
    whenever i enter(got focus) the textbox i want the text in it to be get selected
    i can use textbox.selstart and textbox.sellenth but have many text boxs(48)
    do i have to write it for each and every text box

    (using VB net)
    Please help
    with Regards
    sameer Mulgaonkar

  2. #2
    Frenzied Member dynamic_sysop's Avatar
    Join Date
    Jun 2003
    Location
    Ashby, Leicestershire.
    Posts
    1,142
    you could add a handler for all the textboxes , then use SelectAll() , eg:
    VB Code:
    1. [Color=Blue]Private[/color] [Color=Blue]WithEvents[/color] tb [Color=Blue]As[/color] TextBox
    2.  
    3.     [Color=Blue]Private[/color] [Color=Blue]Sub[/color] Form1_Load([Color=Blue]ByVal[/color] sender [Color=Blue]As[/color] System.Object, [Color=Blue]ByVal[/color] e [Color=Blue]As[/color] System.EventArgs) [Color=Blue]Handles[/color] [Color=Blue]MyBase[/color].Load
    4.         [Color=Blue]Dim[/color] ctl [Color=Blue]As[/color] Control
    5.         [Color=Blue]For[/color] [Color=Blue]Each[/color] ctl [Color=Blue]In[/color] [Color=Blue]Me[/color].Controls
    6.             [Color=Blue]If[/color] [Color=Blue]TypeOf[/color] ctl [Color=Blue]Is[/color] TextBox [Color=Blue]Then
    7. [/color]                [Color=Blue]AddHandler[/color] ctl.Enter, [Color=Blue]AddressOf[/color] tb_Enter
    8.             [Color=Blue]End[/color] [Color=Blue]If
    9. [/color]        [Color=Blue]Next
    10. [/color]    [Color=Blue]End[/color] [Color=Blue]Sub
    11.  
    12. [/color]    [Color=Blue]Private[/color] [Color=Blue]Sub[/color] tb_Enter([Color=Blue]ByVal[/color] sender [Color=Blue]As[/color] [Color=Blue]Object[/color], [Color=Blue]ByVal[/color] e [Color=Blue]As[/color] System.EventArgs) [Color=Blue]Handles[/color] tb.Enter
    13.         [Color=Blue]Dim[/color] txtbox [Color=Blue]As[/color] TextBox = [Color=Blue]DirectCast[/color](sender, TextBox)
    14.         txtbox.SelectAll()
    15.     [Color=Blue]End[/color] [Color=Blue]Sub[/color]
    ~
    if a post is resolved, please mark it as [Resolved]
    protected string get_Signature(){return Censored;}
    [vbcode][php] please use code tags when posting any code [/php][/vbcode]

  3. #3
    Lively Member matt3011's Avatar
    Join Date
    May 2002
    Location
    France
    Posts
    82
    You could Also make your own control :

    Create a new class myTextBox that inherits the class TextBox :
    VB Code:
    1. Public Class myTextBox
    2.       Inherits TextBox
    3.      
    4.     Private Sub Enter(ByVal sender As Object, ByVal e As   System.EventArgs) Handles mybase.Enter
    5.         mybase.SelectAll()
    6.     End Sub
    7.  
    8.  
    9. End Class

  4. #4
    Banned
    Join Date
    Jul 2003
    Location
    New delhi
    Posts
    143
    hi

    u can use select all property

    like

    textbox1.SelectAll()


    Biswajit das

  5. #5

    Thread Starter
    Lively Member sameer spitfire's Avatar
    Join Date
    Nov 2001
    Location
    India
    Posts
    120
    tHANKS A LOTS I WILL TRY SELECTALL()

    one more small thing how i can chatch page Up/page down on a SSTAB Control
    with Regards
    sameer Mulgaonkar

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

    Question Re: selecting text in the text box

    Is there a special trick for when a user clicks into the text box? 'Cause i can't get it to select everything when a user clicks in the text box.

    Code:
        Private Sub TextBox2_Enter(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox2.Enter
            TextBox2.SelectAll()
        End Sub
    ~Peter


  7. #7
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949

    Re: selecting text in the text box

    Quote Originally Posted by MrGTI
    Is there a special trick for when a user clicks into the text box? 'Cause i can't get it to select everything when a user clicks in the text box.

    Code:
        Private Sub TextBox2_Enter(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox2.Enter
            TextBox2.SelectAll()
        End Sub
    It does select it. You can copy it to another Text field. It just doesn't highlight it.
    Taxes
    The more I learn about VB.NET the more I like dBaseIII Plus

    The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.

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

    Unhappy

    It does select it. You can copy it to another Text field. It just doesn't highlight it.
    ooooooooh. So i guess i want to know how to highlight the text. My bad.
    ~Peter


  9. #9
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949

    Re: selecting text in the text box

    Hi,

    "tHANKS A LOTS I WILL TRY SELECTALL()"

    But you will still have to enter it a lot of times, or put a a lot of handles on.

    Matt3011's suggestion means you do not have to write the code more than once.
    Taxes
    The more I learn about VB.NET the more I like dBaseIII Plus

    The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.

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

    Question Re: selecting text in the text box

    Any help in figuring out how to highlight the entire text in a TextBox when a user clicks in the text box?

    Nothing i try will highlight the text (when a user clicks into a text box).
    ~Peter


  11. #11
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949

    Re: selecting text in the text box

    Quote Originally Posted by MrGTI
    Any help in figuring out how to highlight the entire text in a TextBox when a user clicks in the text box?

    Nothing i try will highlight the text (when a user clicks into a text box).
    I've had no success with that either, but there must be a way. If we get no joy on this thread I will start a specific one.
    Taxes
    The more I learn about VB.NET the more I like dBaseIII Plus

    The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.

  12. #12

    Thread Starter
    Lively Member sameer spitfire's Avatar
    Join Date
    Nov 2001
    Location
    India
    Posts
    120

    Re: selecting text in the text box

    Thanks for the reply but one thing u missed that i know the selectall property but my promblem is i have all most 48 - 60 text box on the form and i don't want to repeat the code "Selectall"
    with Regards
    sameer Mulgaonkar

  13. #13
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949

    Re: selecting text in the text box

    Quote Originally Posted by sameer spitfire
    Thanks for the reply but one thing u missed that i know the selectall property but my promblem is i have all most 48 - 60 text box on the form and i don't want to repeat the code "Selectall"
    You have not indicated to which of the replies you are referring.

    I repeat:

    If you use Matt3011's suggestion you will only have to enter the code once.

    Do you object to that?
    Taxes
    The more I learn about VB.NET the more I like dBaseIII Plus

    The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.

  14. #14
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949

    Re: selecting text in the text box

    Quote Originally Posted by taxes
    I've had no success with that either, but there must be a way. If we get no joy on this thread I will start a specific one.
    Hi,

    Looks like the ONLY event which doesn't highlight the text when you use SelectAll() is the GotFocus

    Try it in Click, MouseDown, MouseUp etc.

    With acknowledgments to Brownmonkey
    Taxes
    The more I learn about VB.NET the more I like dBaseIII Plus

    The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.

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

    Re: selecting text in the text box

    The GotFocus/Enter events don't work with SelectAll when you click into the text box. So i created a special procedure that i call from the MouseHover event.
    ~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