views:

25

answers:

1

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.

+1  A: 

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);
Dave