1
 Rectangle Location =  new Rectangle(X , Y, W, H);
 var TextFormat = new StringFormat() { Alignment = StringAlignment.Far };
 string Text = "RRRR1234567890123456789012345678901234567890RRRR";
 e.Cache.DrawString(Tekst,_Font,_Brush, Location, TextFormat);

Hi,

I am using this code to right-align the string 'Text' within the rectangle 'Location'. And it works fine if the width 'W' is bigger than the width of the string

iTextWidth = (int)(e.Graphics.MeasureString(Text, _Font).Width);

But if width 'W' is smaller than iTextWidth, it still shows for example RRRR1234567890123 in stead of 8901234567890RRRR

What do I do wrong

1 Answers1

0

Found it !

Bar = "RRRR1234567890123456789012345678901234567890RRRR";
TextFormatFlags flags =     TextFormatFlags.RightToLeft | TextFormatFlags.Right;
TextRenderer.DrawText(e.Graphics, Bar, _Font, Location, Color.Black, flags);
e.Graphics.DrawRectangle(Pens.Transparent, Location);