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
Printable View
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
Do you mean highlight the text contained with in the text box?
highlight the textbox itself so i will know where i am.
You could change the back color when the text box gets focus and then change it back on lost focus.
i was using this statement txtName.BackColor = System.Drawing.Color.Aqua
that should work, does it?
yeah but it stays on the name textbox and when i click on the address textbox its normal with a white background
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.
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:
Private Sub TextBox_Enter(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.Enter, TextBox2.Enter DirectCast(sender, TextBox).BackColor = Color.Blue End Sub Private Sub TextBox_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.Leave, TextBox2.Leave DirectCast(sender, TextBox).BackColor = SystemColors.Window End Sub
where to implement the TextBox_Enter() and the TextBox_Leave (), is it the the form_load
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.
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.