Resizable GoButton

Hi!

In my project I have a IDButton class derived from GoButton. I'm trying to make the button resizable without any luck. Any hints?
regards,
nampla
--------------------------------------------
IDButton but = new IDButton();
but.Position = new PointF(100, 100);
but.Movable = true; but.Selectable = true; but.AutoRescales = false; but.Resizable = true; but.ActionEnabled = false; Doc.Add(but);

GoButton doesn’t support resizing. The LayoutChildren for GoButton just computes the rectangle for the icon and label, then wraps the TopLeftMargin and BottomRightMargin around that. You could, I suppose, make it resizable by adjusting the margins… I’ll look to see if that’s practical in this case.

Here you go… see caveats below

[code]
public class ResizableButton : GoButton {
public ResizableButton() {
}
public override void DoResize(GoView view, RectangleF origRect, PointF newPoint, int whichHandle, GoInputState evttype, SizeF min, SizeF max) {
if (this.Label != null &&
whichHandle == TopLeft || whichHandle == MiddleTop || whichHandle == TopRight ||
whichHandle == MiddleLeft || whichHandle == MiddleRight ||
whichHandle == BottomLeft || whichHandle == MiddleBottom || whichHandle == BottomRight) {
SizeF oldtl = this.TopLeftMargin;
SizeF oldbr = this.BottomRightMargin;
RectangleF labr = this.Label.Bounds;
RectangleF oldr = labr;
oldr.X -= oldtl.Width;
oldr.Y -= oldtl.Height;
oldr.Width += oldtl.Width + oldbr.Width;
oldr.Height += oldtl.Height + oldbr.Height;
RectangleF newr = ComputeResize(oldr, newPoint, whichHandle, min, max, CanResize());
this.TopLeftMargin = new SizeF(Math.Max(0, labr.Left - newr.Left), Math.Max(0, labr.Top - newr.Top));
this.BottomRightMargin = new SizeF(Math.Max(0, newr.Right - labr.Right), Math.Max(0, newr.Bottom - labr.Bottom));
} else {
base.DoResize(view, origRect, newPoint, whichHandle, evttype, min, max);
}
}
public override void OnLostSelection(GoSelection sel) {
this.ActionEnabled = true;
base.OnLostSelection(sel);
}
public override void OnGotSelection(GoSelection sel) {
this.ActionEnabled = false;
base.OnGotSelection(sel);
}
}
[/code]
1. ActionEnabled is turned off to avoid problems of resize/clicking both trying to happen at the same time.
2. By disabling Action, you also make the button movable. You can set Movable = false if you want.
3. The code above doesn't support the GoButton.Icon. To add support for that, you'd have to change
RectangleF labr = this.Label.Bounds;
to be the Union of the Label.Bounds and Icon.Bounds.

Jake, many thanks for your help!!!

I modified your code to keep button label centered at all times - at the end of margin calculations I added:
this.Label.Center = this.Center;
This helps, however, the button's background is not repainted fully. Say, if I drag sizing point to the right to make button wider. Label shifts to the right as well, but all area to the left of the label is white, not the specified background colour. Clicking on left sizing point causes repaint. Is there some way to force the repaint?
Thanks again
nampla

Hmmmm… I tested this quite a bit and didn’t see any problems. Can you post the code you use to create the button, I’ll give it a try with that.

Hi!

Thank you for your reply. The constructor looks like this
[Serializable] public class IDButton : ResizableButton, IElement { public IDButton() { Movable = true; Selectable = true; Resizable = true;

ActionEnabled = false;
this.Label.Text = “Button”;

}

}
Buttons are created and added to the GoDocument derived object.
IDButton but = new IDButton(); Doc.Add(but);
And this is what the button looks like after some resizing was done
Regards,
nampla

Sorry, I can’t reproduce what you’re seeing. Since you just joined the forum, I’m assuming this is still a fairly simple “getting started” app… Can you send me the whole project? Send it to godiagram [at] the domain above.

Hello!

Thank you for your reply! What I'm doing here, is porting/rewriting in C# our old and rather big C++ project, which was using Go++. As I can see from the old code, we could not get resizable button there neither, so we wrote a class which was faking CGoButton, and was resizable via dragging, and via SetSize, etc. (BTW, I spent some time today trying to get Size or Bounds to work for ResizableButton class - no much success yet. )
Maybe you can suggest some ideas in the same vein of faking the button - some 3Dborder effects for raised and sunken edge around RounderRectangle, or something similar?
And I'll try to make a simple demo application to work on ResizableButton.
Many thanks
nampla