Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
825 views
in Technique[技术] by (71.8m points)

c# - Drawstring word wrap or display entire text

This is the output i get when i use DrawString.

I=Smith,John II=Johnson,Mark III=Anderson,James IV=William,Craig V=Ford,He...

page is a float datatype which value is based on e.PageSettings.Margins.Left;

e.Graphics.DrawString(Text, new System.Drawing.Font("Arial", 8F, FontStyle.Regular), Brushes.Black, page, 30);

In the above example, it is

e.Graphics.DrawString(Text, new System.Drawing.Font("Arial", 8F, FontStyle.Regular), Brushes.Black, page, 30);

I tried using this

StringFormat format = new StringFormat();            
format.FormatFlags = StringFormatFlags.FitBlackBox;

 e.Graphics.DrawString(Text, new System.Drawing.Font("Arial", 8F, FontStyle.Regular), Brushes.Black, page, 30, format);

How do i expand/word wrap so that i can have the entire words instead of '...' at the end?

I=Smith,John II=Johnson,Mark III=Anderson,James IV=William,Craig V=Ford,Henry

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You can "word wrap" the text by using a bounding rectangle.

Use Graphics.DrawString Method (String, Font, Brush, RectangleF, StringFormat)

The RectangleF specifies the draw area and it will automatically "wrap" your text for you.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...