469,621 Members | 1,714 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,621 developers. It's quick & easy.

some questions about controls

Hi,
here is exactly what I want to try and do. On a simple level, when the user
clicks on a textbox the matching label will change colors to hightlight the
which field they are editing. By Default, I always label my labels and
textboxes the same with the exception of the first 3 character....
txtTextbox and the label would be lblTextbox.
Hears the tricky part. I want to have one procedure to do this, this
procedure will be called on the gotfocus event of the textbox(?for each
textbox) and then check the readonly properity of that textbox, if it is
true colors will stay the same, otherwise change foreground and background.
What makes this complecated is this, I don't want to have to put this code
on each gotfocus event of a textbox, maybe sometype of global object
handling event? The other thing is I am taking the name of the textbox and
striping the first 3 character off and tring to set a temp object(label) by
that name to change the colors.
Any idea and or samples you could should me?
Thanks Brian

Sep 2 '08 #1
7 919
Brian,

This kind of things are typicaly done by using the Tag property of the
controls.

http://msdn.microsoft.com/en-us/libr...ntrol.tag.aspx

Cor
"Brian" <bs********@community.nospamschreef in bericht
news:OK**************@TK2MSFTNGP03.phx.gbl...
Hi,
here is exactly what I want to try and do. On a simple level, when the
user clicks on a textbox the matching label will change colors to
hightlight the which field they are editing. By Default, I always label
my labels and textboxes the same with the exception of the first 3
character.... txtTextbox and the label would be lblTextbox.
Hears the tricky part. I want to have one procedure to do this, this
procedure will be called on the gotfocus event of the textbox(?for each
textbox) and then check the readonly properity of that textbox, if it is
true colors will stay the same, otherwise change foreground and
background.
What makes this complecated is this, I don't want to have to put this code
on each gotfocus event of a textbox, maybe sometype of global object
handling event? The other thing is I am taking the name of the textbox
and striping the first 3 character off and tring to set a temp
object(label) by that name to change the colors.
Any idea and or samples you could should me?
Thanks Brian
Sep 2 '08 #2
really, i didn't get much from that, can you explain a bit more?

"Cor Ligthert[MVP]" <no************@planet.nlwrote in message
news:D8**********************************@microsof t.com...
Brian,

This kind of things are typicaly done by using the Tag property of the
controls.

http://msdn.microsoft.com/en-us/libr...ntrol.tag.aspx

Cor
"Brian" <bs********@community.nospamschreef in bericht
news:OK**************@TK2MSFTNGP03.phx.gbl...
>Hi,
here is exactly what I want to try and do. On a simple level, when the
user clicks on a textbox the matching label will change colors to
hightlight the which field they are editing. By Default, I always label
my labels and textboxes the same with the exception of the first 3
character.... txtTextbox and the label would be lblTextbox.
Hears the tricky part. I want to have one procedure to do this, this
procedure will be called on the gotfocus event of the textbox(?for each
textbox) and then check the readonly properity of that textbox, if it is
true colors will stay the same, otherwise change foreground and
background.
What makes this complecated is this, I don't want to have to put this
code on each gotfocus event of a textbox, maybe sometype of global object
handling event? The other thing is I am taking the name of the textbox
and striping the first 3 character off and tring to set a temp
object(label) by that name to change the colors.
Any idea and or samples you could should me?
Thanks Brian

Sep 2 '08 #3
On Mon, 1 Sep 2008 22:31:36 -0400, "Brian"
<bs********@community.nospamwrote:
>Hi,
here is exactly what I want to try and do. On a simple level, when the user
clicks on a textbox the matching label will change colors to hightlight the
which field they are editing. By Default, I always label my labels and
textboxes the same with the exception of the first 3 character....
txtTextbox and the label would be lblTextbox.
Hears the tricky part. I want to have one procedure to do this, this
procedure will be called on the gotfocus event of the textbox(?for each
textbox) and then check the readonly properity of that textbox, if it is
true colors will stay the same, otherwise change foreground and background.
What makes this complecated is this, I don't want to have to put this code
on each gotfocus event of a textbox, maybe sometype of global object
handling event? The other thing is I am taking the name of the textbox and
striping the first 3 character off and tring to set a temp object(label) by
that name to change the colors.
Any idea and or samples you could should me?
Thanks Brian

I would create a subclass of the Textbox class and put your code in
it, then use that class instead of Textbox on your form. Override the
OnGotFocus method. Alternatively you could wire up the GotFocus event
of all of the textboxes to one event handler routine.

To find the label corresponding to the textbox use the form's Controls
collection Find method.

Another approach would be to build a UserControl that contains a
Textbox and a Label.
Sep 2 '08 #4
With that said, my two favorite options are to put both the textbox
and the label into a user control, this encapsulates the entire
behavior and will make it easier on your developers if the spec
changes, for example half the labels get highlighted in green and the
others in red. My other recommended way would be to use Control.Find
to find the label, but this could get expensive processor wise so it
might not be viable (or you might look into doing the search
asynchronously).

Thanks,

Seth Rowe [MVP]
http://sethrowe.blogspot.com/
Sep 2 '08 #5
Jack Jackson wrote:
On Mon, 1 Sep 2008 22:31:36 -0400, "Brian"
<bs********@community.nospamwrote:
>Hi,
here is exactly what I want to try and do. On a simple level, when the user
clicks on a textbox the matching label will change colors to hightlight the
which field they are editing. By Default, I always label my labels and
textboxes the same with the exception of the first 3 character....
txtTextbox and the label would be lblTextbox.
Hears the tricky part. I want to have one procedure to do this, this
procedure will be called on the gotfocus event of the textbox(?for each
textbox) and then check the readonly properity of that textbox, if it is
true colors will stay the same, otherwise change foreground and background.
What makes this complecated is this, I don't want to have to put this code
on each gotfocus event of a textbox, maybe sometype of global object
handling event? The other thing is I am taking the name of the textbox and
striping the first 3 character off and tring to set a temp object(label) by
that name to change the colors.
Any idea and or samples you could should me?
Thanks Brian


I would create a subclass of the Textbox class and put your code in
it, then use that class instead of Textbox on your form. Override the
OnGotFocus method. Alternatively you could wire up the GotFocus event
of all of the textboxes to one event handler routine.

To find the label corresponding to the textbox use the form's Controls
collection Find method.

Another approach would be to build a UserControl that contains a
Textbox and a Label.
That's the route I went, encapsulating both Label and Textbox in a
single UserControl. OK, it's a bit of a pain mucking about aggregating
or overriding some of the properties to "get at" the TextBox and Label
via the UserControl wrapper, but IMHO, it's well worth the effort.

BTW, according to MSDN, we supposed to /avoid/ using OnGotFocus and
OnLostFocus (and their corresponding events) and should be using OnEnter
and OnLeave instead. No idea why; that's just what Our Friends in
Redmond now "recommend".

HTH,
Phill W.
Sep 2 '08 #6
IMHO, Using a UserControl to encapsulate is a very clean approach .

Regards,

Trevor Benedict
MCSD

"rowe_newsgroups" <ro********@yahoo.comwrote in message
news:88**********************************@y21g2000 hsf.googlegroups.com...
With that said, my two favorite options are to put both the textbox
and the label into a user control, this encapsulates the entire
behavior and will make it easier on your developers if the spec
changes, for example half the labels get highlighted in green and the
others in red. My other recommended way would be to use Control.Find
to find the label, but this could get expensive processor wise so it
might not be viable (or you might look into doing the search
asynchronously).

Thanks,

Seth Rowe [MVP]
http://sethrowe.blogspot.com/

Sep 2 '08 #7
Brian <bs********@community.nospamwrote:
"Cor Ligthert[MVP]" <no************@planet.nlwrote in message
Brian,

This kind of things are typicaly done by using the Tag property of the
controls.
http://msdn.microsoft.com/en-us/libr...ntrol.tag.aspx

really, i didn't get much from that, can you explain a bit more?
Since the names are similar, you have a procedure that does a one time
match -- set the tag of each textbox to the corresponding label, then
in your gotfocus event use the tag to set the label.

--
J.B. Moreno
Sep 6 '08 #8

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Newbee Adam | last post: by
2 posts views Thread by Kelvin Tran | last post: by
5 posts views Thread by SharpSmith | last post: by
10 posts views Thread by weird0 | last post: by
reply views Thread by devrayhaan | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.