connecting user controls in c sharp
-
I have created a smalll prototype like Ms visio. In my program i can add controls(rectangle, ellipse,..) to the panel and move them with mouse. But the problem is connecting them with lines so that the objects and lines should move together. Can anybody help me... :confused: samitha
-
I have created a smalll prototype like Ms visio. In my program i can add controls(rectangle, ellipse,..) to the panel and move them with mouse. But the problem is connecting them with lines so that the objects and lines should move together. Can anybody help me... :confused: samitha
You could traverse your "control"-collection/array/etc and use the center of each "control" as the start/end-point of your line? R.a.m
-
I have created a smalll prototype like Ms visio. In my program i can add controls(rectangle, ellipse,..) to the panel and move them with mouse. But the problem is connecting them with lines so that the objects and lines should move together. Can anybody help me... :confused: samitha
A common approach is to define a base class from which all shapes derive. You would define a property on this class that is either a collection or array (which is actually a static collection and list) that stores points. If you want, you could define this property as virtual and provide default connection points. If you declare it as abstract, then every derivative must override it. For any classes where you want to return a custom list of connection points, override the property (assuming it's optionally using a virtual property) and return coordinates of connection points. Then, these connection point classes that you store maintain a list of other controls' connection points (which should have a member that returns the control they're a connection point for). When painting the container/surface, you draw a line between each connection point that is related to another. This is the reason you define a base class - so you can refer to every shape through it's abstract base class. This is polymorphism. If you search CodeProject, you should find a couple examples, IIRC.
Microsoft MVP, Visual C# My Articles