A piece of code for the notepad printing function

Source: Internet
Author: User

A contract printing function has been prepared recently. The text in the contract is rich text, which has a certain format but is not limited to the content entered. I have not found any related articles on the Internet. I wrote a notepad printing function below, but I can only use the same font and change pages.
String strprinttext;
Private void printdocumentemediprintpage (Object sender, system. Drawing. Printing. printpageeventargs E)
{
System. Drawing. Font font = new font ("", 14 );
Graphics G = E. graphics;
Float cyfont = font. getheight (g );
Stringformat strfmt = new stringformat ();
Rectanglef rectffull, rectftext;
Int ichars, ilines;

If (G. visibleclipbounds. x <0)
{
Rectffull = E. marginbounds;
}
Else
{
Rectffull = new rectanglef (
E. marginbounds. Left-(E. pagebounds. Width-
G. visibleclipbounds. width)/2,
E. marginbounds. Top-(E. pagebounds. Height-
G. visibleclipbounds. Height)/2,
E. marginbounds. Width, E. marginbounds. Height );
}

Rectftext = rectanglef. Inflate (rectffull, 0,-2 * cyfont); // remove the two rows and print the title and page number.

Int idisplaylines = (INT) math. Floor (rectftext. Height/cyfont); // calculate the number of rows that can be printed
Rectftext. Height = idisplaylines * cyfont; // calculate the height that can be officially printed

Strfmt. trimming = stringtrimming. word;

If (strprinttext. Length = 0)
{
E. Cancel = true;
Return;
}
G. drawstring (strprinttext, Font, brushes. Black, rectftext, strfmt); // print all text

G. measurestring (strprinttext, Font, rectftext. Size, strfmt, out ichars, out ilines); // gets how many characters can be printed in this area
Strprinttext = strprinttext. substring (ichars); // remove the printed characters.
E. hasmorepages = (strprinttext. length> 0); // determines whether there are other words to print.

}

Private void printdocument1_beginprint (Object sender, system. Drawing. Printing. printeventargs E)
{

Strprinttext = richtextbox1.text;
}

 

I wonder if there is any good way to deal with rich text.

 

 

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.