Draggable Node Labels

Using the Processor demo, I’ve changed the ActivityNode class to inherit from GoGeneralNode instead of GoIconicNode. The original code supports Dragging of the node label via override of OnLayerChanged() setting this.Draggable = true;

since DraggableLabel is a prop of GoIconicNode only I’ve tried to change that line to

this.BottomLabel.Movable = true;

but the label is not movable…

Here is a GoGeneralNode with a BottomLabel that is draggable…



notes:

1. no “DraggableLabel” property, I’m assuming that’s true.

2. no support for TopLabel… you could add that back in at LayoutLabels()

3. I haven’t tested this much, and haven’t done any Undo/Redo testing.



<br />using System; <br />using System.ComponentModel; <br />using System.Drawing; <br />using System.Resources; <br />using System.Windows.Forms; <br />using Northwoods.Go; <br /> <br />namespace QuickGoDiagramForm { <br /> [Serializable] <br /> public class GeneralMovableLabel : GoGeneralNode { <br /> public GeneralMovableLabel() { <br /> } <br /> <br /> public override void LayoutChildren(GoObject childchanged) { <br /> base.LayoutChildren(childchanged); <br /> GoObject icon = this.Icon; <br /> if (icon == null) return; <br /> bool draggableLabel = true; // always draggable... no public property <br /> GoText label = this.BottomLabel; <br /> if (label != null) { <br /> // if DraggableLabel is true, let the user drag it around without moving <br /> // any other children of this node <br /> if (draggableLabel && childchanged == label && !Initializing) { <br /> // remember where the label now is relative to the icon <br /> myLabelOffset = new SizeF(label.Left - icon.Left, label.Top - icon.Top); <br /> return; // don't position port or anything else <br /> } <br /> else if (myLabelOffset.Width > -99999) { // place it relative to the icon <br /> label.Position = new PointF(icon.Left + myLabelOffset.Width, icon.Top + myLabelOffset.Height); <br /> } <br /> else { // put the label below the icon <br /> label.SetSpotLocation(MiddleTop, icon, MiddleBottom); <br /> } <br /> } <br /> } <br /> <br /> protected override void LayoutLabels() { <br /> //base.LayoutLabels(); <br /> } <br /> <br /> [Description("The offset of the Label relative to the Icon")] <br /> public virtual SizeF LabelOffset { <br /> get { return myLabelOffset; } <br /> set { <br /> SizeF old = myLabelOffset; <br /> if (old != value) { <br /> myLabelOffset = value; <br /> Changed(ChangedLabelOffset, 0, null, MakeRect(old), 0, null, MakeRect(value)); <br /> if (!this.Initializing) { <br /> LayoutChildren(null); <br /> } <br /> } <br /> } <br /> } <br /> <br /> public override void ChangeValue(GoChangedEventArgs e, bool undo) { <br /> switch (e.SubHint) { <br /> //case ChangedDraggableLabel: <br /> //this.DraggableLabel = (bool)e.GetValue(undo); <br /> //return; <br /> case ChangedLabelOffset: <br /> this.LabelOffset = e.GetSize(undo); <br /> return; <br /> default: <br /> base.ChangeValue(e, undo); <br /> return; <br /> } <br /> } <br /> <br /> public const int ChangedLabelOffset = 2655; <br /> private SizeF myLabelOffset = new SizeF(-99999, -99999); // used when Width > -99999 <br /> <br /> } <br />} <br /> <br />

Copied you class and instanciated it like this on a winform with GoView control:

GeneralMovableLabel ml = new GeneralMovableLabel();
ml.Initialize(null, 0, “toptxt”, “bottomtxt”, 2, 2);
ml.BottomLabel.Movable = true;
ml.Icon = new GoDrawing(GoFigure.Chevron);
goView1.Document.Add(ml);

…but bottomLabel still doesn’t move when I try to drag it in the goView control

Sorry, I forgot a bit… after the ml.Initialize() do



ml.BottomLabel.Selectable = true;

Now we’re talking! Thanks!