473,385 Members | 1,753 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,385 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
1 1241
The problem you're going to have is that the two controls do not have a
reference to the other. This means that one control on the form needs to know
how to find the other.

Is there a need for the controls to be separated? For instance, do you need
to have the felxibility to place them in different locations on the form?

It depends on the requirements that you have. For instance, if this was
something that you were going to use once on one form, you might be better
off raising an event from one usercontrol and then writing the code into the
form's event handler to manipulate the second control.

If you were going to use these controls often (on numerous forms) or
multiple sets of these controls on any given form, you might be better off
providing a property within the second control that you could access at
design-time (via the properties window) that allowed you to pick the control
that you wanted to bind it to at runtime. You would do this by creating a
class that inherits from ControlDesigner and then link it to your actual
usercontrol by adding Attributes to your control's class.

For example:

<Designer(GetType(MyControlDesigner))> _
Public Class UserControl1
Inherits System.Windows.Forms.UserControl
' Control's inner workings
End Class

Friend Class MyControlDesigner
Inherits ControlDesigner
' Control Designer's inner workings
End Class

Have a search around for information on Control Designers if this idea seems
interesting.

Hope this helps,

-Eric

"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.

Jan 6 '06 #2

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

Similar topics

0
by: Tim Haughton | last post by:
I've just released an article on using Test Driven Development with C# and Windows Forms. GUI's are often difficult to test, so I thought it might be of interest. The article along with the...
0
by: Sinisa | last post by:
I have a Windows form which has multiple groups of the same window controls. I wanted to create a control class that has the standard controls in one. something like: public class Sensor :...
5
by: Dave | last post by:
How do I check in a Windows Forms app if any controls have changed? I have a form that collects data, and I want to prompt the user if they try to exit the app, or load a new file, without saving...
6
by: | last post by:
Just a general question... When working with a form containing a treeview or similar control... if you need to show different form fields depending on what is selected in the treeview then what...
8
by: Alison | last post by:
Hi, Al I am trying to design a user interface which provides both menus and toolbars for some users to click on whatever they want to do, at the same time, I would like to have a console window...
4
by: Rod Gill | last post by:
Hi, I have a form that when opened in the designer appears of the screen. The form selector can't be dragged (or resized) and if I scroll right and down to centralise it the form simply jumps...
4
by: tshad | last post by:
What would be a good way to check programmatically whether a service was running? We have a service that dies periodically and I need to check to see if this service is running. I know how to...
1
by: mfunkmann | last post by:
Hi, I recently got an error and I don't know how to fix it: Error 1 'System.Data.DataColumn' does not contain a definition for 'Windows' C:\c#\CsharpPRO\Form1.Designer.cs 304 77 CsharpPRO I...
21
by: Dan Tallent | last post by:
In my application I have a form (Customer) that I want to be able to open multiple copies at once. Within this form I have other forms that can be opened. Example: ZipCode. When the user enters...
9
by: Scott Stark | last post by:
Hello, I'm *just* delving into Windows forms-based programming without the benefit of any books, etc. I have a background in light ASP.NET work, so forgive me if this is a really basic question...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.