471,317 Members | 1,872 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

Windows forms and user controls

Hello everyone,

I have a windows form that has 2 child usercontrols i created and added
inside, control1 has a label that displays some text based on
activities i do in control2, my question is how do i update the label
text inside control1 from control2? previously i got around this issue
by using properties and static variables but this doesn't work with
form controls such as the label i have.

Any solution would be highly appreciated.

Cheers,

Maya.

Jan 5 '06 #1
4 1055
Maya wrote:
Hello everyone,

I have a windows form that has 2 child usercontrols i created and added
inside, control1 has a label that displays some text based on
activities i do in control2, my question is how do i update the label
text inside control1 from control2? previously i got around this issue
by using properties and static variables but this doesn't work with
form controls such as the label i have.

Any solution would be highly appreciated.

Cheers,

Maya.


Sounds to me like your user controls should be one control.

Best way to do this in your current setup is to have Control2 fire off
an event when Control1 needs updating. Catch the event in your form and
have the form update control1.

Chris
Jan 5 '06 #2
Thanks Chris,

Why do you think i should have only one control? my current form
contains few portions each one has a control to occupy, for example,
control1 is taking care of header values on the top of the form, and
control2 is a container for a TreeView object which retrieves
continuous updates from a database. Do you think this could be designed
in a better way?

Thanks again.

Maya.

Jan 5 '06 #3
If it makes more sense that they be two controls, then they should be
two controls. Your label, then, is something like a generic "show
header information" control?

Anyway, Chris has the solution: control2 should expose an event with a
name relating to what the control does and what happened to it
(ReceivedUpdate or something), and it's up to the enclosing form to
listen for this event and update control1 whenever that event happens.

There are other funky ways of hooking sibling controls together (I've
done it) but they're highly unusual.

Jan 6 '06 #4
Thanks Bruce, i try to follow the easiest solution whenever its
possible, i hope the events solution is the easiest!

Jan 6 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Tim Haughton | last post: by
4 posts views Thread by Rod Gill | last post: by
4 posts views Thread by tshad | last post: by
21 posts views Thread by Dan Tallent | last post: by
reply views Thread by rosydwin | last post: by

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.