GoLabelLink.MidLabel's WrappingWith

I am not able to dynamically change the WrappingWidth of the MidLabel so that the text will wrap or not depends on the link’s width. Please show me how.

Thanks,
Henry

When are you changing it? What’s the behavior?

Originally, the link’s label is displayed on 2 lines as I wanted. When the link’s width is increased (by dragging one of the end nodes further apart), the label then is displayed on 1 line. However, when the link’s width is decreased, the label’s appearance stays the same.

Thanks,
Henry

Can you post the relevant code?

Creation of GoLabeledLink:
Public Sub New(ByVal Transition_Def As TransitionDef, ByVal FromNode As StateNode, ByVal ToNode As StateNode)
Me.Editable = False
Me.Deletable = False
Me.Style = GoStrokeStyle.Bezier
Me.ToArrow = True
Me.RealLink.PenColor = Color.Black
Me.RealLink.PenWidth = 1
Me.RealLink.HighlightWhenSelected = True
Me.RealLink.HighlightPen = New Pen(Color.GreenYellow, 5)
Me.FromPort = FromNode.Port
Me.ToPort = ToNode.Port
Dim cond As GoText = New GoText
cond.Selectable = False
cond.Editable = False
cond.EditableWhenSelected = False
cond.Multiline = True
cond.Wrapping = True
cond.WrappingWidth = Me.Width
cond.Text = Transition_Def.TransitionName
Me.MidLabel = cond
End Sub
Try to resize link's label:
Private Sub ResizeLinkLabel(ByVal Transition_Def As TransitionDef)
If Transition_Def.GoObject Is Nothing Then Exit Sub
Dim Link As Transition = WorkflowViewer.Document.FindPart(Transition_Def.GoObject.PartID)
If Link IsNot Nothing Then
Dim cond As GoText = New GoText
cond.Selectable = False
cond.Editable = False
cond.EditableWhenSelected = False
cond.Multiline = True
cond.Wrapping = True
cond.WrappingWidth = Link.Width
cond.Text = Transition_Def.TransitionName
Link.MidLabel = cond
End If
End Sub

Link.Width, for a GoLabeledLink, includes the width of the labels (they are children of the GoGroup containing the GoLink). So… the problem is your use of Link.Width, it never gets smaller than the width of the label.



The following code works… and enforces a minimum width as well.



[Serializable]

public class AdjustingWidthLabeledLink : GoLabeledLink {



public AdjustingWidthLabeledLink() {

GoText t = new GoText();

t.Text = “this is text that should wrap”;

t.Multiline = true;

t.Wrapping = true;

t.Editable = true;

this.MidLabel = t;

}



protected override void PositionMidLabel(GoObject lab, PointF a, PointF b) {

base.PositionMidLabel(lab, a, b);

GoText t = lab as GoText;

if (t != null) {

t.WrappingWidth = Math.Max(40, Math.Abs(a.X - b.X));

}

}

}



couple of notes:



1) you don’t have to create a new GoText, setting the WrappingWidth is enough.



2) no special reason I used PositionMidLabel as the hook, it was just a convenient hook in the middle of LayoutChildren. You could also use LayoutMidLabel.



and… the positioning may be better if you setting the WrappingWidth before calling the base method… I didn’t play with that.

Ahh, that was my problem!

Jake, thanks for the code. It works great!
Henry