I added a OnConnectionAdded Handler to reject
connections from a shape to itself.
<pre>
protected bool OnConnectionAddedHandler(object sender,
ConnectionEventArgs e)
{
if (e.From.BelongsTo == e.To.BelongsTo)
{
MessageBox.Show("This Shape cannot connect to
itself.");
return false;
}
return true;
}
</pre>
This works fine, except when you drag an existing
connection end to a different shape:
1) Add 2 shapes
2) Add a connection from one shape to the other
3) Select the end of the connection on shape 2 and drag
it back to a connector on the first shape (making a
connection from one connector on the first shape to
another connector on the same shape)
4) The MessageBox in the handler pops up properly, but
upon dismissal, it crashes in the first line of:
<pre>
Netron.GraphLib.Connection.Paint()
{
if(!From.BelongsTo.Layer.Visible ||
!To.BelongsTo.Layer.Visible) return;
...
</pre>
Both "From" and "To" are null at this point.
Logged In: YES
user_id=1246985
I can'r follow this since I don't know how to preform Step
3. (neither with my Shapes or ComboControl.
Would assume throuh the Selection and moving from Shape 2
(please tell me how/where this is done) and condition has
be changed.
- this (I assume/guess) condition should be restored
before OnPaint.
Only guessing until Step 3 is explained.
Logged In: YES
user_id=1246985
Noted for further consideration, other options requested.
Logged In: YES
user_id=434021
Sorry, I probably wasn't very clear. I'll try again.
First: Netron allows you to "mouse-down" the <end> of a
connection and drag it over to a different connector and
drop it. This causes the Connection to move from the old
Connector to the new Connector.
1) Add 2 BasicNode shapes.
2) Add a connection from shape 1 (top connector) to shape 2
(top connector)
3) Next, Mouse-down over the top connector on shape 2.
4) Drag over to the LEFT connector on shape 1 and drop it
(mouse-up).
This attempts to create a connection from the Top connector
on shape 1, to the Left connector also on shape 1.
The OnConnectionAdded() handler should fire and detect that
you're adding a connection from a shape, back to itself.
(My sample handler pops a message box and then returns
false, indicating that the connection is not allowed).
The Connection.Paint() method throws with dereferencing null
pointers.
Logged In: YES
user_id=434021
Oh, one other point I didn't mention:
The OnConnectionAdded handler works fine, and properly
rejects the connection, if you attempt to add a *new*
connection between two connectors on the same shape.
It only fails if you try to drag an existing connection off
of one shape and back onto the same shape that the
connection originated from. Form a connection from itself,
to itself.