In this case it might be easier to extend the textbox to add this
behavior and then in any case where you want the behavior use your
extended textbox.
Otherwise, create a helper class like:
class TextboxHighlighter
shared sub Wrap(tbox as textbox)
addhandler tbox.enter, me.enter
addhandler tbox.lostfocus, me.lostfocus
end sub
shared sub enter(sender as object, e as eventargs)
directcast(sender, textbox).backcolor = Color.Aquamarine
end sub
shared sub lostfocus(sender as object, e as eventargs)
directcast(sender, textbox).backcolor = color.white
end sub
end class
then for each textbox just call
TextboxHighlighter.Wrap(textbox)
if you want the original color instead of color.white you can store
the original colors in a hashtable. should really be able to store it
in a single variable since the lostfocus event of the active textbox
should never fire before the enter event of another, but I'd be sure
to test that assumption before suggesting that way.
Which you use (inheritance vs decoration) is a matter of preference.
HTH,
Sam
On Fri, 7 Jan 2005 12:45:01 -0800, Joseph
<Jo****@discussions.microsoft.com> wrote:
Hello.
What I am tiring to accomplish is highlight and restore the backcolor of "a"
textbox when a cursor hits or leaves it with a general sub and a handler that
contains the fields I want to change. The code below gives you an idea of
what I would like to accomplish and it only demonstrates one cycle or event.
There would be in my thinking another general sub to return the textbox to
the original color.
Private Sub HighLight(ByVal Sender As Object, ByVal e As EventArgs) Handles
txt1.Enter, txt2.Enter
Sender.BackColor = Color.Aquamarine
End Sub
Thanks in Advance!
Brain Dead