Joseph,
I would use something like what Herfried showed, for other options I would
consider see my response in the entire thread that Cor referenced:
http://groups-beta.google.com/group/...22186d980ed9fe
Here is a more complete version of what Herfried shows originally based on
the above thread:
Imports System.ComponentModel
Public Class TextBoxEx
Inherits TextBox
Public Shared ReadOnly Property DefaultFocusColor() As Color
Get
Return SystemColors.Info
End Get
End Property
Public Event FocusColorChanged As EventHandler
Private m_focusColor As Color
Private m_backColor As Color
Public Sub New()
m_focusColor = DefaultFocusColor
m_backColor = MyBase.BackColor
End Sub
<Category("Appearance"), _
Description("The background color used when the control has focus")> _
Public Property FocusColor() As Color
Get
Return m_focusColor
End Get
Set(ByVal value As Color)
m_focusColor = value
OnFocusColorChanged(EventArgs.Empty)
End Set
End Property
Protected Overridable Sub OnFocusColorChanged(ByVal e As EventArgs)
RaiseEvent FocusColorChanged(Me, e)
End Sub
Public Sub ResetFocusColor()
m_focusColor = DefaultFocusColor
End Sub
Public Function ShouldSerializeFocusColor() As Boolean
Return Not m_focusColor.Equals(DefaultFocusColor)
End Function
Protected Overrides Sub OnEnter(ByVal e As System.EventArgs)
MyBase.OnEnter(e)
MyBase.BackColor = m_focusColor
End Sub
Protected Overrides Sub OnLeave(ByVal e As System.EventArgs)
MyBase.OnLeave(e)
MyBase.BackColor = m_backColor
End Sub
Protected Overrides Sub OnBackColorChanged(ByVal e As System.EventArgs)
MyBase.OnBackColorChanged(e)
If MyBase.BackColor.Equals(m_focusColor) Then Exit Sub
m_backColor = MyBase.BackColor
End Sub
End Class
On your form instead of using TextBox controls you would use the above
TextBoxEx controls.
Hope this helps
Jay
"Joseph" <Jo****@discussions.microsoft.com> wrote in message
news:CB**********************************@microsof t.com...
Hello,
Here is my solution below that works but can be improved upon. The
improvement that I seek is how to define the handler that handles the txt1
and txt2 controls in an automated fashion. If I add three more textboxes
to
my winform, I do not want to have to change the hadler evertime I make
changes.
Private txtColor As Color = Color.LightSkyBlue
Private txtOrig As Color
Private Sub HighLight(ByVal Sender As Object, ByVal e As EventArgs)
Handles
txt1.Enter, txt2.Enter
txtOrig = DirectCast(Sender, TextBox).BackColor()
DirectCast(Sender, TextBox).BackColor = txtColor
End Sub
Private Sub LowLight(ByVal Sender As Object, ByVal e As EventArgs) Handles
txt1.Leave, txt2.Leave
DirectCast(Sender, TextBox).BackColor = txtOrig
End Sub
Thanks in Advance!
Joseph