473,511 Members | 16,660 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Handler manipulation of controls

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

Nov 21 '05 #1
3 1007

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


Nov 21 '05 #2
I'm doing exactly what Joseph wants to do with two little routines:

Friend Sub TBEnter(ByVal sender As Object, ByVal e As System.EventArgs)
DirectCast(sender, TextBox).BackColor = Color.GhostWhite
End Sub

Friend Sub TBLeave(ByVal sender As Object, ByVal e As System.EventArgs)
DirectCast(sender, TextBox).BackColor = Color.White
End Sub

Having already established the event handlers:
dim ctrl as Control
For Each ctrl in MyForm.Controls
If TypeOf ctrl is TextBox then
AddHandler ctrl.Leave, AddressOf TBLeave
AddHandler ctrl.Enter, AddressOf TBEnter
EndIf
Next
Terp

"Samuel R. Neff" <bl****@newsgroup.nospam> wrote in message
news:63********************************@4ax.com...

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 thatcontains the fields I want to change. The code below gives you an idea ofwhat 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 tothe original color.

Private Sub HighLight(ByVal Sender As Object, ByVal e As EventArgs) Handlestxt1.Enter, txt2.Enter
Sender.BackColor = Color.Aquamarine

End Sub

Thanks in Advance!
Brain Dead

Nov 21 '05 #3
I'm doing exactly what Joseph wants to do with two little routines:

Friend Sub TBEnter(ByVal sender As Object, ByVal e As System.EventArgs)
DirectCast(sender, TextBox).BackColor = Color.GhostWhite
End Sub

Friend Sub TBLeave(ByVal sender As Object, ByVal e As System.EventArgs)
DirectCast(sender, TextBox).BackColor = Color.White
End Sub

Having already established the event handlers:
dim ctrl as Control
For Each ctrl in MyForm.Controls
If TypeOf ctrl is TextBox then
AddHandler ctrl.Leave, AddressOf TBLeave
AddHandler ctrl.Enter, AddressOf TBEnter
EndIf
Next
Terp

"Samuel R. Neff" <bl****@newsgroup.nospam> wrote in message
news:63********************************@4ax.com...

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 thatcontains the fields I want to change. The code below gives you an idea ofwhat 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 tothe original color.

Private Sub HighLight(ByVal Sender As Object, ByVal e As EventArgs) Handlestxt1.Enter, txt2.Enter
Sender.BackColor = Color.Aquamarine

End Sub

Thanks in Advance!
Brain Dead

Nov 21 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
7886
by: Ashish Shridharan | last post by:
Hi All I have been trying to add a control to the header cell of a datagrid on my ASP.NET page. These controls are defined in the HTML as ASP.NET web controls. They are being added into the...
0
1883
by: Anonieko Ramos | last post by:
Answer. Use IHttpHandler. thanks Ro ry for coming up with this code. It processes css file to add variables. neat idea using System; using System.IO; using System.Text; using...
0
1794
by: Novice | last post by:
Hey all, I've already posted this question and two posters offered suggestions and they worked - but now I would like to know why - and if possible the answer to a second question. Here is my...
5
1698
by: Russell Smallwood | last post by:
Hello all, Why can't I wire up an event during the "Raise PostBackEvent" stage of a postback? Just in case this is the wrong question, the situation: deep in the bowls of some code-behind...
10
3857
by: Wylbur via DotNetMonster.com | last post by:
Hello to all of you geniuses, I'm having a problem trying to get an Init handler to fire for a Placeholder control at the initialization phase. I’ve posted this problem to 3 other ASP.NET...
7
1803
by: Jay Douglas | last post by:
Greetings, I have a Windows form application that (naturally) instantiates all sorts of objects. I have a base object that contains an event. Lots of other objects inherit from this event. ...
1
1668
by: kaczmar2 | last post by:
I have an ASP.NET page where controls are created dynamically, and I have an issue where one event handler creates another set of controls, and then adds event handlers to those controls. The...
2
2308
by: ccbalapatel | last post by:
Hi, We have recently converted our code to ASP.NET 2.0. We have an user control that is embedded inside the page. The user control has a link button and the event handler for the link button is...
2
3899
by: John Kotuby | last post by:
Hi guys, I am converting a rather complicated database driven Web application from classic ASP to ASP.NET 2.0 using VB 2005 as the programming language. The original ASP application works quite...
0
7355
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7510
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5066
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4737
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3225
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3213
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1576
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
781
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
447
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.