TextAlignment with homemade multiline label

  • Thread starter Thread starter Torbjorn Stavas
  • Start date Start date
T

Torbjorn Stavas

Hi there!

Have made my own custom control (with help of Alex Yakhnins' excellent article
"Design time functionality..."), that enables wordwrap for labels.

I'm using this code to get the text wrapped:

RectangleF wrapRect = (RectangleF) this.ClientRectangle;
wrapRect.X+=2;
wrapRect.Y+=2;

SolidBrush b = new SolidBrush(ForeColor);
gr.DrawString(this.Text, Font, b, wrapRect);
b.Dispose();

Is there a way to align the text, when you're using a rectangle to draw a
string. It's easy when using
gr.DrawString(text1, Font, b, posX, posY); , since you have the possiblity to
specify y and x, but i really like to use the rectangle, 'cause i get the
wordwrap "for free".

So, anyone got any suggestions?

//Kind Regards, Torbjorn
 
Unfortunatelly, CF doesn't allow to do that. My workaround was a little bit
involed - split the text up in single lines and draw each line separatedly.

HTH... Alex
 
Back
Top