Visual C # dialog box (2)

Source: Internet
Author: User

In fact, there is not much to talk about page settings (pagesetupdialog). Now, I will list the common attributes in pagesetupdialog.

1. common attributes of pagesetupdialog

 

Allowmargins sets whether the margin can be edited by alloworientation, whether the "direction" single direction allowpaper can be used, whether the paper size can be edited by allowprinter, and whether the "Printer" button document can be used to obtain the printdocument set by the printer. minmargins minimum margin that can be selected

That's easy. Let's take a look at the following. What about the more important stuff? About printing.

Print pre-renewal and Printing

Printing is a feature that we often use in Windows programming. It used to be very difficult to work, but in Microsoft. the printing in the net framework is provided to us by components, but it is still a little troublesome, so it is specially written for your reference.

1. In the. NET environment, when it comes to printing, the printdocumet class cannot be mentioned. printdocument belongs to the namespace system. Drawing. printing. The printdocument class is the core of printing.Code.

To implement printing, you must first construct a printdocument object to add a printing event,
Printdocument. printpage + = new printpageeventhandler (this. printdocument_printpage)
Printing actually calls the graphics class method for drawing. The following code is rewritten according to the routine provided on msdn. Msdn print routine address:

Http://msdn.microsoft.com/library/default.asp? Url =/library/en-US/cpref/html/frlrfsystemdrawingwintingprintdocumentclasstopic. asp. If you are interested, change it.

The following is the printdocument_printpage I have rewritten:
The C #. Net tutorial you are reading is: Visual C # dialog box full contact.

 

private void printdocument_printpage (Object sender, system. drawing. printing. printpageeventargs e)
{< br> float linesperpage = 0; // The row number of the page
float ypos = 0; // print the vertical position of the string
int COUNT = 0; // The row counter
float leftmargin = E. marginbounds. left; // left margin
float topmargin = E. marginbounds. top; // top margin
string line = NULL; // line string
color CLR = richtextbox1.selectioncolor; // The current print color, in my Program Supports printing of different colors
solidbrush B = new solidbrush (CLR); // brush
fnt = richtextbox1.selectionfont; // The current print font
linesperpage = E. marginbounds. height/fnt. getheight (E. graphics); // Number of printable lines per page
file: // print a page row by row
while (count {
ypos = topmargin + (count * fnt. getheight (E. graphics);
E. graphics. drawstring (line, fnt, B, leftmargin, ypos, new stringformat ();
count ++;
}< br> file: // If the page is printed and the line is not empty, the next printing event is triggered.
file: // In the next printing, linereader will automatically read the last unprinted content. Linereader can record the currently read location
If (line! = NULL)
E. hasmorepages = true;
else
E. hasmorepages = false;
}

The entire print task can be completed here. After constructing printdocument_printpage, you can print and print the pre-release.

Ii. Print the Pre-Export Dialog Box (printpreviewdialog)

The print prepaster control is used to display the effect of a printed document after printing. The print pre-release dialog box contains buttons such as print, zoom, single page or multi-page, and close.

The print prefill dialog box does not have many attributes and is called by showdialog. The above implementation code is as follows:

Private void printpreviewbtn_click (Object sender, system. eventargs E)
{
Linereader = new stringreader (richtextbox1.text );
Try
{
Printpreviewdialog printpreviewdialog1 = new printpreviewdialog ();
Printpreviewdialog1.document = printdocument;
Printpreviewdialog1.formborderstyle = formborderstyle. fixed3d;
Printpreviewdialog1.showdialog (this );
}
Catch (exception excep)
{
MessageBox. Show (excep. message, "print error", messageboxbuttons. OK, messageboxicon. Error );
Return;
}
}

It's easy to write printdocument_printpage.

3. Print the dialog box (printdialog)

1. The printdialog dialog box has the following attributes:

Allowprinttofile disable or use the "print to file" check box allowselection disable or use the "selected content" Single-choice allowsomepages disable or use the "page" Single-choice button document to get the printdocument printtofile set by the printer to print to a file" check box whether showHelp is selected to control whether to display the "help" button shownetwork control whether to display the "network" button

 

2. Use the following code:

Private void printdialogbtn_click (Object sender, system. eventargs E)
{
Printdialog = new printdialog ();
Printdialog. Document = printdocument;
If (printdialog. showdialog ()! = Dialogresult. Cancel)
{
Try
{
Printdocument. Print ();
}
Catch (exception ex)
{
MessageBox. Show (ex. Message );
}
}
}

At this point, all the dialogs are finished, and the headers are big.

The preceding dialog box can be completed in the IDE environment of vs.net. In this case, to illustrate the problem, we will separate it step by step.

Summary

In our tutorial, the file dialog box (filedialog), fontdialog, colordialog, printpreviewdialog, and printdialog are described) and the Print dialog box (printdialog). The file dialog box (filedialog) includes the open file dialog box (openfiledialog) and save the file dialog box (savefiledialog. With the above foundation, you can easily write a simple notebook

 

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.