Text padding in a GoText


#1

I need a bordered text but between the text and the border it must be a little empty space something like padding.

The default obtained by deriving a GoText class is that the border is very close to the text.

How can a little space be inserted between the text and the border?

I tried to override the Bounds get (wrong bewhavior: grows at every
touch), ComputeBounds (does not do anything in this case),
ComputeResize (does not do anything in this case).

Thanks for any help


#2

Well, I suppose the easiest solution is to add a space character at each end of the string. But that would be kludgy and wouldn’t help if you want more space between the border at the top and at the bottom of the text object.
I suggest you implement your own decoration by overriding Paint and ExpandPaintBounds, instead of using the predefined GoText.Bordered property. I haven’t tested the following code, but it ought to be something like:
public override Paint(Graphics g, GoView view) {
if (PaintGreek(g, view)) return;
base.Paint(g, view);
RectangleF r = this.Bounds;
Pen borderpen = new Pen(this.TextColor);
GoShape.DrawRectangle(g, view, borderpen, null, r.X-2, r.Y-1, r.Width+4, r.Height+2);
borderpen.Dispose();
}
public override RectangleF ExpandPaintBounds(RectangleF rect, GoView view) {
RectangleF r = base.ExpandPaintBounds(rect, view);
r.X -= 2;
r.Width += 4;
r.Y -= 1;
r.Height += 2;
return r;
}
Of course you can fiddle around with the actual distances, and the color and other characteristics of any border decoration too.
Basically overriding GoObject.Paint allows you to do anything you want, but you need to override ExpandPaintBounds in order to let the GoView know how much of the screen needs to be repainted for each object.


#3

Ok it worked thanks.

Just a little note: in the case of the background not transparent the
background must also be paint because the base.Paint just take into
consideration the old size and a little transparent space appear
between the text and the border.


#4
Where is the function PaintGreek() ?

#5

This topic is talking about the GoText class; overrides of Paint and ExpandPaintBounds would be in a class you define that inherits from GoText.