How to make GoBalloon resizable

Hi,

We’re using GoBalloon to implement comments attached to other diagram items and we’ve got some problems. How can I achieve following behavior of GoBalloon:

  • comment is resizable (user can drag handle and resize balloon)
  • text is displayed multiline and adapts to size of comment

I thought that implementing this will be quite easy task but it wasn’t. I definitely missed something and I’ll be thankful for any tip.

Regards
Lukasz

Actually, it is pretty easy to modify the ResizableComment class to get what you want. Basically you want resizing to resize the Label instead of resizing the Background shape.

To do this, change ResizableComment to inherit from GoBalloon, initialize the GoText label to support being resized, and change DoResize to set the Label.Bounds instead of setting the margins. Also, since ResizableComment also supports a GoCollapsibleHandle, we need to position the Handle relative to the Label instead of relative to the Background.

But if you strip out all of the IGoCollapsible support, you get:

[code] [Serializable]
public class ResizableBalloon : GoBalloon {
public ResizableBalloon() {
this.Resizable = true;
GoText lab = this.Label;
if (lab != null) {
lab.Wrapping = true;
lab.AutoResizes = false;
lab.Clipping = true;
lab.StringTrimming = StringTrimming.EllipsisCharacter;
}
}

public override void DoResize(GoView view, RectangleF origRect, PointF newPoint,
             int whichHandle, GoInputState evttype, SizeF min, SizeF max) {
  GoText lab = this.Label;
  if (lab != null && whichHandle != GoBalloon.AnchorHandle) {
    RectangleF newr = ComputeResize(origRect, newPoint, whichHandle, min, max, CanResize());
    SizeF oldtl = this.TopLeftMargin;
    SizeF oldbr = this.BottomRightMargin;
    newr.X += oldtl.Width;
    newr.Y += oldtl.Height;
    newr.Width -= oldtl.Width + oldbr.Width;
    newr.Height -= oldtl.Height + oldbr.Height;
    lab.Bounds = newr;
    lab.WrappingWidth = newr.Width;
  } else {
    base.DoResize(view, origRect, newPoint, whichHandle, evttype, min, max);
  }
}

}[/code]

Walter, thanks for the above code snippet, exactly what I needed to add resizable GoComments to my view.

When first created the ResizableBallon is 10 by 10 pixels. I would like to make a larger initial size, and can’t do it.

I’ve overridden Bounds, ComputeBounds, OnBoundsChanged and Changed and can’t get the initial node to be anything but 10 by 10.

Any suggestions?

Thank You

I tried to set the label width after other initialization.
It works when the resizable ballon object is created.
See the blue line of code.

[Serializable]
  public class ResizableBalloon : GoBalloon {
    public ResizableBalloon() {
      this.Resizable = true;
      GoText lab = this.Label;
      if (lab != null) {
        lab.Wrapping = true;
        lab.AutoResizes = false;
        lab.Clipping = true;
        lab.StringTrimming = StringTrimming.EllipsisCharacter;
        lab.Width = 100;
      }
    }
  }

Is there a question?

Setting the size of the GoText inside the GoComment node worked.

Thank you huanyue!