Here is a sample code I'm using and which is working:
SizeF textSize = g.MeasureString(
this.Text,
this.Font
);
float maxWidth = this.Width;
if(textSize.Width > maxWidth)
{
// textSize.Height *= ((textSize.Width / maxWidth) + 1);
// textSize.Height += (textSize.Width / maxWidth) * 2;
textSize.Height = 1000;
textSize.Width = maxWidth;
}
RectangleF labelRect = new RectangleF(0,0,0,0);
switch(this.TextAlign)
{
case ContentAlignment.TopLeft:
labelRect = new RectangleF(
this.Location.X,
this.Location.Y, // + (this.Height - textSize.Height) /2,
textSize.Width,
textSize.Height
);
break;
case ContentAlignment.TopCenter:
labelRect = new RectangleF(
this.Location.X + (this.Width - textSize.Width) / 2,
this.Location.Y, // + (this.Height - textSize.Height) /2,
textSize.Width,
textSize.Height
);
break;
case ContentAlignment.TopRight:
labelRect = new RectangleF(
this.Location.X + this.Width - textSize.Width - 3,
this.Location.Y, // + (this.Height - textSize.Height) /2,
textSize.Width,
textSize.Height
);
break;
}
g.DrawString(
this.Text,
this.Font,
new SolidBrush(this.ForeColor),
labelRect
);
You will have to adapt a little the code since I draw directly on the form
but the idea is to calculate the rectangle where the label will reside...
Steve
<(E-Mail Removed)> a écrit dans le message de news:
(E-Mail Removed)...
I have designed a cusom control called ImageButton with an image and a
text. The text is drawn on the control with
Graphics.DrawString (String, Font, Brush, RectangleF, StringFormat)
the StringFormat (fmt) is setup to enable word-wrapping, horizontal and
vertical centering with
fmt.Alignment = StringAlignment.Center;
fmt.LineAlignment = StringAlignment.Center;
This works just great in design time, and when executed on the PC, but
in PPC2003SE (device or emulator) text is not word wrapped.
Any ideas ?
Søren B. Christensen