Results 1 to 12 of 12

Thread: [RESOLVED] highlight active textbox

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Nov 2005
    Posts
    208

    Resolved [RESOLVED] highlight active textbox

    hi i have a form which contains the id number, name, address, dob and tel no. how i would like to highlight the textbox when the user clicked on a textbox or pressed the tab key. thanks

  2. #2
    Fanatic Member
    Join Date
    Aug 2005
    Location
    Wisconsin
    Posts
    788

    Re: highlight active textbox

    Do you mean highlight the text contained with in the text box?

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Nov 2005
    Posts
    208

    Re: highlight active textbox

    highlight the textbox itself so i will know where i am.

  4. #4
    Fanatic Member
    Join Date
    Aug 2005
    Location
    Wisconsin
    Posts
    788

    Re: highlight active textbox

    You could change the back color when the text box gets focus and then change it back on lost focus.

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Nov 2005
    Posts
    208

    Re: highlight active textbox

    i was using this statement txtName.BackColor = System.Drawing.Color.Aqua

  6. #6
    Fanatic Member
    Join Date
    Aug 2005
    Location
    Wisconsin
    Posts
    788

    Re: highlight active textbox

    that should work, does it?

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Nov 2005
    Posts
    208

    Re: highlight active textbox

    yeah but it stays on the name textbox and when i click on the address textbox its normal with a white background

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

    Re: highlight active textbox

    You may like to download the XP Common Controls library from the link in my signature. It includes the XPTextBox class that has a very elegant way to indicate focus. The .NET 2.0 version is currently in beta.
    Attached Images Attached Images  
    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

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

    Re: highlight active textbox

    If you want to do it with the BackColor then you need to change the colour for every TextBox when it receives focus and when it loses focus.
    VB Code:
    1. Private Sub TextBox_Enter(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.Enter, TextBox2.Enter
    2.         DirectCast(sender, TextBox).BackColor = Color.Blue
    3.     End Sub
    4.  
    5.     Private Sub TextBox_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.Leave, TextBox2.Leave
    6.         DirectCast(sender, TextBox).BackColor = SystemColors.Window
    7.     End Sub
    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

  10. #10

    Thread Starter
    Addicted Member
    Join Date
    Nov 2005
    Posts
    208

    Re: highlight active textbox

    where to implement the TextBox_Enter() and the TextBox_Leave (), is it the the form_load

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

    Re: highlight active textbox

    They are methods. You don't put method definitions inside other method defintions. To create an event handler you open the code window, select the control from the drop-down list at the top-left then select the event from the top-right. The IDE will create the appropriate empty event handler for you. You can then change the name of the method and add additional events to the Handles clause. That's exactly what I did to produce the code above. I created handlers for the TextBox1.Enter and TextBox1.Leave events, then I added the code to the body of each, changed the name to be more general and added the TextBox2 events to the Handles clauses.
    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

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

    Re: [RESOLVED] highlight active textbox

    I actually just tried using the XP Common Controls XPFocusProvider for the first time myself. It allows TextBoxes to be rendered normally, which the XPTextBox and XPTextBoxProvider do not, and it gives a consistent visual cue for all controls, not just TextBoxes. It is a bit more subtle and stylish than changing the BackColor too. I highly recommend it. I changed the defaults a little. The default colours are orange and dark orange, the line weight is 2 and the distance from the control is 2. I have changed that to ActiveCaption and InactiveCaption, 1 and 0 to make it more subdued.
    Attached Images Attached Images  
    Last edited by jmcilhinney; Feb 27th, 2006 at 10:48 PM.
    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

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