开发者

Printing a page number in each printed page in c#

开发者 https://www.devze.com 2023-03-22 02:11 出处:网络
I am new to using the printdocument feature in c# and needed some help. I need to print a header on each page that the printer prints and i 开发者_如何学Goneed the page number on it.

I am new to using the printdocument feature in c# and needed some help. I need to print a header on each page that the printer prints and i 开发者_如何学Goneed the page number on it.

I am currently using a string, concatenating to it and then printing it line by line in the printDocument_PrintPage method. i want to concatenate a variable to the string i print that keeps track of the page number that its being printed on.

Is this possible? This is my code so far for calling the printpage method:

    printDialog1.Document = printDocument1;

    if (printDialog1.ShowDialog() == DialogResult.OK)
        this.printDocument1.Print();


Yes. Just create a page counter field in the class that will be handling the print events. Something like:

private int _pageCount = 1;

The in your print page handler just append it to your header string and then increment it before exiting the handler. Something like:

private void PrintPageEventHandler(...
{
     string pageHeader = "Page # " + pageCount;

     //  printing code here

     pageCount++;
}
0

精彩评论

暂无评论...
验证码 换一张
取 消