473,396 Members | 1,805 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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 1041
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Newbee Adam | last post by:
If I program in vb.net will my program be accessible via a browser, or do I need to use the webbrowser active x control like in vb 6. would the program reside on a webserver like IIS or apache? ...
3
by: Ken Varn | last post by:
I am just starting the process of creating ASP.NET server controls. I have created controls for .NET applications, but have just started with ASP.NET. I am a little confused about some areas that...
2
by: Wee Bubba | last post by:
i started by designing my web page using frames. i had my data entry form in an upper form and my data rows displaying in a lower frame. i soon discovered that ASP.NET is not really meant for...
2
by: Dave | last post by:
I am converting an ASP Classic web site to an ASP.NET application and have some real basic formatting or design questions. (The classic ASP site has both code (forms) and content pages.) 1.When...
2
by: Kelvin Tran | last post by:
To whom it may concerns: I have some questions about VB.net 2003 as listed below. 1.. How to print out VB.net design form? 2.. How to create a line graph (Strip chart) in VB.net 2003? 3.. Is...
1
by: TBK | last post by:
I'm trying to finish up an assignment I had for a class and basically I'm stuck. The program is supposed to take information you've entered, put it into an array, display it in a listbox and then...
10
by: Michael | last post by:
Hi Everyone. I have been designing a form with about 100 or so controls and today I pasted some code from another test project into this one and then all the controls on the form disapeared from...
13
by: M.Siler | last post by:
Let me clarify from my last post. I am not using these 4 questions as the sole screening method. Currently in, the Tampa Bay area (Florida) there is an extreme shortage of C# developers. We have...
5
by: SharpSmith | last post by:
hi all the question is more related to architecture and practices and I'll appreciate any opinion i work with asp net 1/2 few years and with any project we developing we meet performance issues...
10
by: weird0 | last post by:
I heard of two c# interview questions that i still clearly don't know and havent understood the concept. One reason is also that I havent worked upon them 1. What is the difference between a...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.