Advice for binding properties of multiple objects

L

Lance

I am looking for some advice for binding properties of
multiple objects that are NOT inherited from
Windows.Forms.Control.

I have a set of PictureBoxes that contain shapes. The
number of PictureBoxes is determined by the user at
runtime. Each PictureBox contains a collection of shapes
that are created and manipulated interactively by the
user. Each shape will always have a corresponding shape
in each of the PictureBoxes. For example, if the user
creates a new line in one of the PicutreBoxes, then a line
will automatically be created in each of the other
PictureBoxes.

What I need to do is make it so that all corresponding
shapes are updated whenever one of the shapes is
modified. For example, lets say the user has created 3
PictureBoxes (PictureBox1, PictureBox2, and PictureBox3)
and that each PictureBox contains 2 Lines (Line1 and
Line2). Now lets say the user moves the StartPoint of
Line2 in PictureBox3 with the mouse. This will cause the
StartPointChanged event to be fired. What I need to do is
update Line2 in PictureBox1 and PictureBox2 so that the
StartPoint property of Line2 is the same in all of the
PictureBoxes.

Does .NET provide any tools for handling this type of
behavior?

Thanks,
Lance
 
J

John Eikanger

Hi, Lance

There's nothing like that built into the framework. You would need to
develop your own objects and notify them when a change is made so that you
can update visually. This would mean redrawing each time the display is
updated like an old storage tube scope. There are some interesting things
you can do with paths, but I'm not sufficiently clear on what you are doing
to be sure if they apply or not.

I would consider posting follow up questions to
microsoft.public.framework.drawing. The folks there are best qualified to
address this question. It isn't managed newsgroup, but it is pretty well
monitored by the GDI team.

Thank you for choosing the MSDN Managed Newsgroups,

John Eikanger
Microsoft Developer Support

This posting is provided “AS IS” with no warranties, and confers no rights.
--------------------
| Content-Class: urn:content-classes:message
| From: "Lance" <[email protected]>
| Sender: "Lance" <[email protected]>
| Subject: Advice for binding properties of multiple objects
| Date: Mon, 1 Dec 2003 09:26:55 -0800
| X-Tomcat-NG: microsoft.public.dotnet.languages.vb
|
| I am looking for some advice for binding properties of
| multiple objects that are NOT inherited from
| Windows.Forms.Control.
|
| I have a set of PictureBoxes that contain shapes. The
| number of PictureBoxes is determined by the user at
| runtime. Each PictureBox contains a collection of shapes
| that are created and manipulated interactively by the
| user. Each shape will always have a corresponding shape
| in each of the PictureBoxes. For example, if the user
| creates a new line in one of the PicutreBoxes, then a line
| will automatically be created in each of the other
| PictureBoxes.
|
| What I need to do is make it so that all corresponding
| shapes are updated whenever one of the shapes is
| modified. For example, lets say the user has created 3
| PictureBoxes (PictureBox1, PictureBox2, and PictureBox3)
| and that each PictureBox contains 2 Lines (Line1 and
| Line2). Now lets say the user moves the StartPoint of
| Line2 in PictureBox3 with the mouse. This will cause the
| StartPointChanged event to be fired. What I need to do is
| update Line2 in PictureBox1 and PictureBox2 so that the
| StartPoint property of Line2 is the same in all of the
| PictureBoxes.
|
| Does .NET provide any tools for handling this type of
| behavior?
|
| Thanks,
| Lance
|
|
|
 
L

Lance

Sorry. I guess I wasn't clear. I have already created
the shape classes that handle the drawing and user
interaction parts. Now all that I need to do is implement
a technique that binds various properties of the shapes.
For example, I want to bind the StartPoint and EndPoint
properties of corresponding line shapes so that all of the
corresponding lines will update their position whenever
one of the lines is moved by the user.

An obvious solution is to create a class that listens to
the shapes' PropertyChanged events and sets the
appropriate values whenever a shape's property changes.
But, is there a better technique than this? I know that
it is easy to bind Control properties, but my shapes don't
inherit from Windows.Forms.Control.

Thanks again,
Lance
 
J

John Eikanger

Hi, Lance

I can come up with lots of ways to do this, but nothing that I would state
authoritatively as better. I would probably handle binding by creating a
collection of like objects and perform the update in the property changed
event for each object. Just add the object to the right collection on
creation. If the number of your objects is small enough or the objects are
going to change groupings, it might be better to use a single collection
with a key property to link the objects of the same type. This solution
does not utilize advanced features to any great extent, but has the
advantage of simplicity, If you are more interested in stretching the
system, go for it. The key is to pick a solution that fits your needs now
and can be readily changed as the requirements evolve.

Thank you for choosing the MSDN Managed Newsgroups,

John Eikanger
Microsoft Developer Support

This posting is provided “AS IS” with no warranties, and confers no rights.
--------------------
| Content-Class: urn:content-classes:message
| From: "Lance" <[email protected]>
| Subject: RE: Advice for binding properties of multiple objects
| Date: Tue, 2 Dec 2003 11:42:31 -0800
| X-Tomcat-NG: microsoft.public.dotnet.languages.vb
|
| Sorry. I guess I wasn't clear. I have already created
| the shape classes that handle the drawing and user
| interaction parts. Now all that I need to do is implement
| a technique that binds various properties of the shapes.
| For example, I want to bind the StartPoint and EndPoint
| properties of corresponding line shapes so that all of the
| corresponding lines will update their position whenever
| one of the lines is moved by the user.
|
| An obvious solution is to create a class that listens to
| the shapes' PropertyChanged events and sets the
| appropriate values whenever a shape's property changes.
| But, is there a better technique than this? I know that
| it is easy to bind Control properties, but my shapes don't
| inherit from Windows.Forms.Control.
|
| Thanks again,
| Lance
|
|
| >-----Original Message-----
| >Hi, Lance
| >
| >There's nothing like that built into the framework. You
| would need to
| >develop your own objects and notify them when a change is
| made so that you
| >can update visually. This would mean redrawing each time
| the display is
| >updated like an old storage tube scope. There are some
| interesting things
| >you can do with paths, but I'm not sufficiently clear on
| what you are doing
| >to be sure if they apply or not.
| >
| >I would consider posting follow up questions to
| >microsoft.public.framework.drawing. The folks there are
| best qualified to
| >address this question. It isn't managed newsgroup, but
| it is pretty well
| >monitored by the GDI team.
| >
| >Thank you for choosing the MSDN Managed Newsgroups,
| >
| >John Eikanger
| >Microsoft Developer Support
| >
| >This posting is provided "AS IS" with no warranties, and
| confers no rights.
| >--------------------
| >| Content-Class: urn:content-classes:message
| >| From: "Lance" <[email protected]>
| >| Sender: "Lance" <[email protected]>
| >| Subject: Advice for binding properties of multiple
| objects
| >| Date: Mon, 1 Dec 2003 09:26:55 -0800
| >| X-Tomcat-NG: microsoft.public.dotnet.languages.vb
| >|
| >| I am looking for some advice for binding properties of
| >| multiple objects that are NOT inherited from
| >| Windows.Forms.Control.
| >|
| >| I have a set of PictureBoxes that contain shapes. The
| >| number of PictureBoxes is determined by the user at
| >| runtime. Each PictureBox contains a collection of
| shapes
| >| that are created and manipulated interactively by the
| >| user. Each shape will always have a corresponding
| shape
| >| in each of the PictureBoxes. For example, if the user
| >| creates a new line in one of the PicutreBoxes, then a
| line
| >| will automatically be created in each of the other
| >| PictureBoxes.
| >|
| >| What I need to do is make it so that all corresponding
| >| shapes are updated whenever one of the shapes is
| >| modified. For example, lets say the user has created 3
| >| PictureBoxes (PictureBox1, PictureBox2, and
| PictureBox3)
| >| and that each PictureBox contains 2 Lines (Line1 and
| >| Line2). Now lets say the user moves the StartPoint of
| >| Line2 in PictureBox3 with the mouse. This will cause
| the
| >| StartPointChanged event to be fired. What I need to do
| is
| >| update Line2 in PictureBox1 and PictureBox2 so that the
| >| StartPoint property of Line2 is the same in all of the
| >| PictureBoxes.
| >|
| >| Does .NET provide any tools for handling this type of
| >| behavior?
| >|
| >| Thanks,
| >| Lance
| >|
| >|
| >|
| >
| >.
| >
|
 

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