Click here to Skip to main content
15,899,662 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear all,

As we focus on any textbox we can change the background colour.
VB
Private Sub TextBox2_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox2.GotFocus
       TextBox2.BackColor = Color.GreenYellow
End Sub


KINDLY GUIDE IF WE HAVE MORE THAN 25 TEXTBOXES AND WANT TO CHANGE ALL THE TEXTBOX COLUR WITH MOVEMENT OF CURSOR ON THAT OR WANT TO SEE THE LOCATION OF CURSOR WITH CHANGING BACKGROUD COLOUR HOW TO SEE THAT
I have more than 25 textboxes and if I want to change all the textbox color with movement of mouse on that, or if I want to see the location of mouse with changing background color. How to see that?
Posted
Updated 14-Sep-10 20:46pm
v2
Comments
Sandeep Mewara 15-Sep-10 2:46am    
P.S.: You already used capital letters which is considered shouting and then you increased the font size of it. Avoid it from next time.
Jatinder Gupta 15-Sep-10 3:12am    
Noted sir, keep in the mind from the next time.

With so many textboxes, I would create a derived TextBox control like this:

VB
Public Class SuperTextBox
    Inherits System.Windows.Forms.TextBox

    Protected Overrides Sub OnGotFocus(ByVal e As System.EventArgs)
        Me.BackColor = Color.GreenYellow
        MyBase.OnGotFocus(e)
    End Sub

    Protected Overrides Sub OnLostFocus(ByVal e As System.EventArgs)
        MyBase.OnLostFocus(e)
        Me.BackColor = SystemColors.Window
    End Sub
End Class


Then I would change all the textbox's types (in the designer file) from System.Windows.Forms.TextBox to the derived SuperTextBox class
 
Share this answer
 
Comments
Simon_Whale 17-Sep-10 11:25am    
Nice answer
Write a common method and pass in the name of the textbox. Or track the list of textboxes through a collection.
 
Share this answer
 
Comments
Jatinder Gupta 15-Sep-10 3:11am    
Kindly explain about that with an example
Johnny J. 17-Sep-10 9:38am    
Possible, but not a good idea with so many textboxes...
You can attach the attribute below to all your textbox to get desired result,

JavaScript
onBlur="this.style.backgroundColor='#ffffff'" 
 
Share this answer
 
Comments
Dalek Dave 15-Sep-10 3:48am    
Good Answer.
Johnny J. 17-Sep-10 9:23am    
Is it? This strikes me as a winforms question - not an ASP.NET question

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900