Open-source: vs. Net printing page settings (pagesetupdialog) always change the value, customize the paper and continuously take the paper problem and solve the source code (1)

Source: Internet
Author: User

Open-source: vs. Net printing page settings (pagesetupdialog) always change the value, customize the paper and continuously take the paper problem and solve the source code (1)
Author: Yangtze River Tributary

Close key: vs. net, print, page Setting Dialog Box
Date: 2006-02-09

Abstr

There are a lot of questions about how to change the settings of printing pages, custom paper, and continuous paper. There are many sayings, some of which are vs. Net bugs, some of which must use APIs, and others...
In fact, we have not thoroughly studied it. Here are some solutions.

When pagesetupdialog is used to print the page setting value, the page margin is entered for each displayed dialog box. When you enter the page Setting dialog box next time, you will find that the original value has changed and then change it again?

Why? This is not a bug in vs.net. In fact, we cannot blame Microsoft for the fact that people are working around the world, but we are using the Chinese version. There is a conversion problem between the metric and the US.

When you use the page Setting Value dialog box, you can drag the control in the toolbox to the window for use. In fact, this is inconvenient and is not conducive to code reuse and unification. I made a printerpagesetting class and encapsulated the dialog box about printing, which is especially convenient to use. I wrote two documents in my blog and listed the csdn homepage as the headlines. The following link is provided:

The implementation and application of the print page settings, printer settings, print preview dialog box in the. NET environment: http://blog.csdn.net/flygoldfish/archive/2004/08/17/77208.aspx
Http://blog.csdn.net/flygoldfish/archive/2004/09/06/95685.aspx

And list the source code of the page Setting dialog box for your reference:

# Region page Setting Dialog Box protected virtual pagesettings showpagesetupdialog (printdocument)
/// <Summary>
/// Page Setting dialog box, which can be used independently
/// </Summary>
/// <Param name = "printdocument"> </param>
/// <Returns> </returns>
/// <Remarks>
/// OPERATOR: Zhou fangyong
/// Modification date:
/// </Remarks>
Protected virtual pagesettings showpagesetupdialog (printdocument)
{
// Check whether printdocument is empty. If it is null, an exception is thrown.
Throwprintdocumentnullexception (printdocument );

// Declare the pagesettings of the returned value
Pagesettings PS = new pagesettings ();

// Declare and instantiate pagesetupdialog
Pagesetupdialog psdlg = new pagesetupdialog ();

PS = printdocument. defaultpagesettings;

Try
{
// Related documents and documents page default settings
Psdlg. Document = printdocument;

Margins Mg = printdocument. defaultpagesettings. margins;
If (system. Globalization. regioninfo. currentregion. ismetric)
{
Mg = printerunitconvert. Convert (Mg, printerunit. display, printerunit. tenthsofamillimeter );
}

// Defaultpagesettings of the backup print document, because it will change after conversion, and the Setting dialog box does not display the original value after clicking the cancel button.
Pagesetaskpsprintdocumentback = (pagesetask) (printdocument. defaultpagesetask. clone ());

Psdlg. pagesettings = psprintdocumentback; // printdocument. defaultpagesettings; // the dialog box is restored when printdocument is canceled.
Psdlg. pagesettings. Margins = mg;

// Display dialog box
Dialogresult result = psdlg. showdialog ();
If (result = dialogresult. OK)
{
PS = psdlg. pagesettings;
Printdocument. defaultpagesettings = psdlg. pagesettings;
}
Else
{

}

}
Catch (system. Drawing. Printing. invalidprinterexception E)
{
Showinvalidprinterexception (E );
}
Catch (exception ex)
{
Showprinterexception (Ex );
}
Finally
{
Psdlg. Dispose ();
Psdlg = NULL;
}

Return pS;
}
# Endregion

At this point, the problem of changing the Setting Dialog Box value on the print page has been solved. In the next (next) article, let's work together to solve the problem of Custom paper and see if custom paper and continuous paper can be implemented without using API at least?

Download all the source code and various types of printing in this article for free. Visit my blog on csdn:
Http://blog.csdn.net/flygoldfish

Disclaimer: This article is copyrighted by Zhou fangyong. If you need to reprint it, please keep the complete content and source.

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.