. Net (C #) printing-multi-region Printing

Source: Internet
Author: User
Tags failover print format
If you want to print more images, use the hasmorepages semantics of printpageeventargs.

We made the following changes to the previous generation:
Added the beginprint and endprint events of printdocument. The beginprint event is used to obtain the printed content. Endprint is used to store resources. In the printpage event of printdocument, the score is displayed.
Base: The beginprint event method is called before the printpage event method.
The pintpage event method is called before the endprintpage event method.
The endprint event method is finally called.Will returnPrintdocument. Print ()Method, the rows are printed.

The process is as follows:
1 Real-world print text examples
2 . Beginprint Event , Used to get the printed content; Pinrtpage Event , Used in various regions; Endprint Event , Used to store resources)
3 , Used for failover Beginprint Event method to get the print content
4 , Used for failover Pinrtpage Event method. Multiple print faces are created, and the root cause is to determine whether multiple rows are printed.
5 , Used for failover Endprint The method of the event, which is used to store the data source, and then print it.

The token generation is as follows:

UsingSystem. IO;
UsingSystem. Drawing. printing;

namespace simpleeditor
{< br> Public partial class simpleeditorform: form
{< br> private string filename = " untitled " ;

// 1. practically print text watermark
printdocument pddocument = New printdocument ();

private string [] lines;
private int linesprinted;
Public simpleeditorform ()
{< br> initializecomponent ();

//2,Zookeeper event

// Specifies the pinrtpage event, which is used to specify the content of each batch.
Pddocument. printpage + =   New Printpageeventhandler (onprintpage );
// Inprint event, used to obtain the printed content
Pddocument. beginprint + =   New Printeventhandler (pddocument_beginprint );
// Specifies the upload endprint event, which is used by the metadata source.
Pddocument. endprint + =   New Printeventhandler (pddocument_endprint );
}

Private   Void Onfileprint ( Object Sender, eventargs E)
{
Try
{
// License Printing
Pddocument. Print ();

/*
* The print () method of printdocument objects is used to parse the printpage event with the help of printcontroller.
*/
}
Catch (Invalidprinterexception ex)
{
MessageBox. Show (ex. Message, " Simple Editor " , Messageboxbuttons. OK, messageboxicon. Error );
Throw ;
}
}

///   <Summary>
///  3, Print content
/// Onbeginprint () is used for each print task worker.
///   </Summary>
///   <Param name = "sender"> </param>
///   <Param name = "E"> </param>
Void Pddocument_beginprint ( Object Sender, printeventargs E)
{
Char [] Param = { ' \ N ' };
Lines = Textboxedit. Text. Split (PARAM );

Int I =   0 ;
Char [] Trimparam = { ' \ R ' };
Foreach ( String S In Lines)
{
Lines [I ++ ] = S. trimend (trimparam );
}
}

///   <Summary>
///  4, Compile multiple print faces
/// Printpage event of printdocument
///   </Summary>
///   <Param name = "sender"> </param>
///   <Param name = "E"> </param>
Private   Void Onprintpage ( Object Sender, printpageeventargs E)
{
/*
* Obtain the string number of each row in the textbox.
* \ N rows
* \ R car return
*/

Int X =   20 ;
Int Y =   20 ;
While (Linesprinted < Lines. length)
{
// The area to be printed
E. Graphics. drawstring (lines [linesprinted ++ ], New Font ( " Arial " , 10 ), Brushes. Black, x, y );

Y+ = 55;

// When the judgment period exceeds one hour, it is allowed to print multiple rows
If (Y > = E. pagebounds. Height -   80 )
{
// Allow printing of many shards
E. hasmorepages =   True ;

/*
* When the haemorepages encoding of printpageeventargs type is true, the notification widget must use the onprintpage () method again to print a plane.
* Printloopi () has a sequence example for each vertex to be printed. If hasmorepages is false, printloop () will stop.
*/
Return ;
}
}

Linesprinted= 0;
//After the scheme is completed, disable the multi-region printing function.
E. hasmorepages= False;

}

///   <Summary>
/// 5, Endprint event, metadata Source
///   </Summary>
///   <Param name = "sender"> </param>
///   <Param name = "E"> </param>
Void Pddocument_endprint ( Object Sender, printeventargs E)
{
// Variable Number of strings occupied and referenced by lines.
Lines =   Null ;
}
}
}

In this way, the multi-region printing function is completed.

Although we have set multi-faceted printing, the printer cannot set the content such as the plane distance. How can we set the print format?

Please refer to the following link:. Net (C #) printing-plane settings

 

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.