[code] [Serializable]
public class NoResizeHandlesLabeledLink : GoLabeledLink {
public NoResizeHandlesLabeledLink() { }
public override GoLink CreateRealLink() {
return new NoResizeHandlesLink();
}
}
[Serializable]
public class NoResizeHandlesLink : GoLink {
public NoResizeHandlesLink() {
this.Orthogonal = true;
this.ToArrow = true;
}
public override void AddSelectionHandles(GoSelection sel, GoObject selectedObj) {
// somewhat wasteful: create all selection handles as normal, ...
base.AddSelectionHandles(sel, selectedObj);
// and then remove the intermediate ones, while leaving the two handles used for relinking
foreach (IGoHandle h in sel.GetHandleEnumerable(this)) {
if (h.HandleID != GoLink.RelinkableFromHandle && h.HandleID != GoLink.RelinkableToHandle) {
h.GoObject.Remove();
}
}
}
}[/code]
Thanks for your reply.
The code I posted works well for me. Are you sure you are using GoLabeledLinks that contain NoResizeHandleLinks with that method override?
Hi Walter,
I’m using the same code that was sent by you, with the override method. Can u send me a snapshot of how exactly the ouput comes for you.
And is there any other way of implementing the same apart for the one provided?
Thanks.
I just created a bunch of different kinds of nodes, linked them together, and then selected everything. I had set GoView.NewLinkClass = typeof(NoResizeHandlesLabeledLink).
Yes, I’m sure there are other ways of implementing the same behavior. But what’s wrong with the one I provided? There’s just an override of GoObject.AddSelectionHandles, which is simple and clear.
[code] [Serializable]
public class NoResizeHandlesLink2 : GoLink {
public NoResizeHandlesLink2() {
this.ToArrow = true;
this.Orthogonal = true;
this.HighlightPen = new Pen(Color.HotPink, 5);
this.HighlightWhenSelected = true;
}
public override void AddSelectionHandles(GoSelection sel, GoObject selectedObj) {
RemoveSelectionHandles(sel);
if (this.PointsCount == 0) return;
if (this.HighlightWhenSelected) {
bool oldskips = this.SkipsUndoManager;
this.SkipsUndoManager = true;
this.Highlight = true;
this.SkipsUndoManager = oldskips;
}
if (this.Relinkable) {
PointF pnt = GetPoint(this.FirstPickIndex);
IGoHandle handle = sel.CreateResizeHandle(this, selectedObj, pnt, RelinkableFromHandle, true);
MakeRelinkingHandle(handle);
pnt = GetPoint(this.LastPickIndex);
handle = sel.CreateResizeHandle(this, selectedObj, pnt, RelinkableToHandle, true);
MakeRelinkingHandle(handle);
}
}
private static void MakeRelinkingHandle(IGoHandle handle) {
GoHandle goh = handle.GoObject as GoHandle;
if (goh != null) {
goh.Style = GoHandleStyle.Diamond;
RectangleF bounds = goh.Bounds;
bounds.Inflate(bounds.Width/6, bounds.Height/6);
goh.Bounds = bounds;
goh.CursorName = "hand";
}
}
public override void RemoveSelectionHandles(GoSelection sel) {
if (this.HighlightWhenSelected) {
bool oldskips = this.SkipsUndoManager;
this.SkipsUndoManager = true;
this.Highlight = false;
this.SkipsUndoManager = oldskips;
}
sel.RemoveHandles(this);
}
}[/code]