Results 1 to 10 of 10

Thread: text "hatch(?)ing"

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jan 2011
    Posts
    154

    text "hatch(?)ing"

    hey guys i need to know how to get a text of a textbox "blued" if focus = true
    ... for not clicking twice.... i mean when you click, background of the text become blue and what you write is replaced with the text...(i dont know what that is called)

  2. #2
    Karen Payne MVP kareninstructor's Avatar
    Join Date
    Jun 2008
    Location
    Oregon
    Posts
    6,713

    Re: text "hatch(?)ing"

    Use Enter and Leave event of a TextBox to alter the background color as shown here where there are three TextBox controls.

    Code:
    Public Class Form3
        Private Sub TextBox1_Enter(ByVal sender As Object, ByVal e As System.EventArgs) _
            Handles TextBox1.Enter, TextBox2.Enter, TextBox3.Enter
            CType(sender, TextBox).BackColor = Color.Blue
        End Sub
        Private Sub TextBox1_Leave(ByVal sender As Object, ByVal e As System.EventArgs) _
            Handles TextBox1.Leave, TextBox2.Leave, TextBox3.Leave
            CType(sender, TextBox).BackColor = Color.FromName("Window")
        End Sub
    
        Private Sub Form3_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) _
            Handles MyBase.Load
            ActiveControl = TextBox3
        End Sub
    End Class

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Jan 2011
    Posts
    154

    Re: text "hatch(?)ing"

    thanks for your answer but i dont think your code will help me but im not sure anyways....my most important goal was not coloring the background...it was the ability of changing a text with getting focus into that textbox and by pressing a button...
    e.g: a text of textbox1 is "123" and i click to that textbox only once...and then press 5 once and the last text is not including "123" in it i hope you understand it and if your code does that im sorry(tell me if it works for that but it didnt seem to doing that).....i got to go ....

  4. #4
    Freelancer akhileshbc's Avatar
    Join Date
    Jun 2008
    Location
    Trivandrum, Kerala, India
    Posts
    7,652

    Re: text "hatch(?)ing"

    I think, this is what you are looking for (if I understand your question):
    vb.net Code:
    1. Private Sub TextBox1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.Click
    2.         TextBox1.SelectAll()
    3.     End Sub
    The SelectAll() of a TextBox will highlight all the text inside it(the blue background that you are referring to seems to be this highlighting). So, you could simply call this method in the Click() event of the TextBox.

    Thus whenever you click on the TextBox, the Click() event is fired and this will call the TextBox's SelectAll() method.

    Hope this helps

    If my post was helpful to you, then express your gratitude using Rate this Post.
    And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
    My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet

    Social Group: VBForums - Developers from India


    Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: text "hatch(?)ing"

    I don't think that handling the Click event is the answer. If you do that, whenever the user tries to click to place the caret within the text, all the text will be selected. It would make more sense to handle the Enter event, so that all the text is selected every time the control receives focus, by mouse or keyboard. That allows the user to click the text while the control already has focus to position the cursor. If the control already has focus and the user wants to select all the text then they just use Ctrl+A, which is the universal Windows shortcut for select all.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Jan 2011
    Posts
    154

    Re: text "hatch(?)ing"

    but i have a lot of textbox must have this procedure how can i make the code handles them all(cant write all of them almost 50 or 60)

  7. #7
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: text "hatch(?)ing"

    Quote Originally Posted by ugur View Post
    but i have a lot of textbox must have this procedure how can i make the code handles them all(cant write all of them almost 50 or 60)
    Select them all in the designer, open the Properties window, click the Events button and then double-click the desired event. That will create one event handler with all controls in the Handles clause. You can also later select one or more controls and then select the existing event handler from the drop-down in the Properties window.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    Jan 2011
    Posts
    154

    Re: text "hatch(?)ing"

    Quote Originally Posted by jmcilhinney View Post
    Select them all in the designer, open the Properties window, click the Events button and then double-click the desired event. That will create one event handler with all controls in the Handles clause. You can also later select one or more controls and then select the existing event handler from the drop-down in the Properties window.
    Code:
    Private Sub TextBox4_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox7.Enter, TextBox6.Enter, TextBox4.Enter, TextBox1.Enter, kS3.Enter, kS2.Enter, kS1.Enter, Cnc.Enter
    'i couldnt figure out what to write here...???
        End Sub

  9. #9
    Fanatic Member BlindSniper's Avatar
    Join Date
    Jan 2011
    Location
    South Africa
    Posts
    865

    Re: text "hatch(?)ing"

    Code:
        Private Sub TextBox4_Enter(sender As Object, e As EventArgs) Handles TextBox4.Enter, TextBox3.Enter, TextBox2.Enter, TextBox1.Enter
            Dim txt As TextBox = DirectCast(sender, TextBox)
            txt.SelectAll()
        End Sub

    Useful CodeBank Entries of mine
    Expand Function
    Code Compiler
    Sudoku Solver
    HotKeyHandler Class

    Read this to get Effective help on VBForums
    Hitchhiker's Guide to Getting Help at VBF

  10. #10

    Thread Starter
    Addicted Member
    Join Date
    Jan 2011
    Posts
    154

    Re: text "hatch(?)ing"

    Quote Originally Posted by BlindSniper View Post
    Code:
        Private Sub TextBox4_Enter(sender As Object, e As EventArgs) Handles TextBox4.Enter, TextBox3.Enter, TextBox2.Enter, TextBox1.Enter
            Dim txt As TextBox = DirectCast(sender, TextBox)
            txt.SelectAll()
        End Sub
    thank you

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