Exchanging values of properties between two components at design time

G

ganeshokade

Dear Experts,
I have to write a C# program with the following requirements. I
have to make two components (call C1 and C2) both of which can be
included by an end user into his project. I have not decided what they
have to be - an ActiveX component or a class library. Each of these
objects has a set of properties. End users will create forms that
contain these components. Now there is a requirement that the value of
one of the properties of component C1 has to be available to C2 at
"design time". The idea is that the end user needs to set the value of
some common properties in only one of the components and the other
components automatically "get" this value. This saves typing time for
the user and prevents users from typing different values for different
components (which is not allowed in our application). Is this possible?
If yes, how? Thanks.

Regards,
Ganesh Okade
 
G

Guest

I have to write a C# program with the following requirements. I
have to make two components (call C1 and C2) both of which can be
included by an end user into his project...
Now there is a requirement that the value of
one of the properties of component C1 has to be available to C2 at
"design time". The idea is that the end user needs to set the value of
some common properties in only one of the components and the other
components automatically "get" this value. This saves typing time for
the user and prevents users from typing different values for different
components (which is not allowed in our application). Is this possible?

Yes, but it's not trivial. To have one component update the properties of
another component at design time, you need to create a custom
ComponentDesigner for your components. Then you need to provide the
IComponentChangeService interface in your ComponentDesigner so that you can
monitor for the ComponentChanged event raised by your other component.

The book "Pro .NET 2.0 Windows Forms and Custom Controls in C#" (Matthew
MacDonald, APress 2006) is an excellent book that details how to do this.

Another possibility is to provide some sort of interprocess communications
between the two components to keep each other in sync. We offer a .NET
component FREE for non-commercial use that provides fast & efficient IPC:

http://www.mini-tools.com/goto/comm
 
S

Sheraz

I believe the easiest solution is to use delegate. Delclare a delegate in C1 and register it in C2. When you want C2 to be notified with changes are made in C1, simply raise it through C1 and pass the values that C2 needs to be notified as Delegate argument.
Hope this would solve your problem.
Sheraz.
 
G

ganeshokade

Dear Timm/Sheraz,
Thank you for your responses.

I have one question regarding the responses from both of you. You
solutions look like they require the component to be "running" for them
to work. At design time will the components really "run"?

Regards,
Ganesh
 
G

Guest

Dear Timm/Sheraz,
Thank you for your responses.
I have one question regarding the responses from both of you. You
solutions look like they require the component to be "running" for them
to work. At design time will the components really "run"?

Yes, that is the "magic" of .NET design time, that your controls and
components are actually running inside the design environment. In some cases
you may not want your component to initialize or execute some aspect during
design time, in which case you may need to perform the following check:

if (this.DesignMode)
// do something only at run-time
 
G

ganeshokade

Hi Timm,
Thanks again for taking time to respond. That's something great
about .NET! Thanks - I guess that resolves my problem.

Regards,
Ganesh Okade
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top