Thursday, April 21, 2011

StringFormat flags : display the whole line

the StringFormat flags permits to differently represent a string in a rectangle.

in this example was used string_format.FormatFlags = StringFormatFlags.NoClip one:

alt text

Question

having

txt = "The quick brown fox jumps over the lazy dog."

can I represent this text entirely as a single line (non-clipped and centered).

I mean, I use a default rectangle without knowing what will be the length of the text, but i know where should be the text center.

From stackoverflow
  • I think the StringFormat.Trimming property is the magic to make this occur, if I understood your question:

    StringFormat format = new StringFormat(StringFormatFlags.NoClip | StringFormatFlags.NoWrap);
    format.Alignment = StringAlignment.Center;
    format.Trimming = StringTrimming.None;
    e.Graphics.DrawString(text, SystemFonts.DefaultFont, Brushes.Black, rect, format);
    

0 comments:

Post a Comment