C # print long string line breaks,

Source: Internet
Author: User

C # print long string line breaks,

The main code is as follows:

StringFormat fmt = new StringFormat (); fmt. lineAlignment = StringAlignment. near; // left-aligned fmt. formatFlags = StringFormatFlags. lineLimit; // automatic line feed // sets the coordinate of Area B in the upper left corner of the text print area, and Size in the print area (rectangle) float mmtopt = 2.835f; unit conversion, mm * 2.835 = Point unit Rectangle r = new Rectangle (B, new Size (Convert. toInt32 (160 * mmtopt), Convert. toInt32 (100 * mmtopt); g. drawString (tb. text, titleFont, new SolidBrush (Color. black), r, fmt );

The following is the code of a software that I developed to automatically print a fixed table:

If (tb. text. trim (). length <28) // Title {g. drawString (tb. text, textFont, new SolidBrush (Color. black), B);} else {StringFormat fmt = new StringFormat (); fmt. lineAlignment = StringAlignment. near; // left-aligned fmt. formatFlags = StringFormatFlags. lineLimit; // automatic line feed // sets the coordinate of Area B in the upper left corner of the text print area, and Size in the print area (Rectangle) float mmtopt = 2.835f; Rectangle r = new Rectangle (B, new Size (Convert. toInt32 (160 * mmtopt), Convert. toInt32 (100 * mmtopt); r. Y = r. y-Convert. toInt32 (2 * mmtopt); Font titleFont = new Font (new FontFamily (""), 13, GraphicsUnit. point); g. drawString (tb. text, titleFont, new SolidBrush (Color. black), r, fmt );}

If the number of characters is less than 28, the default font is used to print the content. If the number of words is too large, the font is reduced, and the coordinates are slightly changed up to automatically print the line feed.

There will still be a single line but a small font, but it cannot be avoided as long as the font is reduced.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.