c#-winform-Print Controls

Source: Internet
Author: User

Control design:

Set the document property of the above button and the remaining controls of the form control (PRINTDIALOG1, etc.) to the corresponding PrintDocument.

Code:

1 usingSystem;2 usingSystem.Collections.Generic;3 usingSystem.ComponentModel;4 usingSystem.Data;5 usingSystem.Drawing;6 usingSystem.Linq;7 usingSystem.Text;8 usingSystem.Threading.Tasks;9 usingSystem.Windows.Forms;Ten  One namespaceYundayin A { -      Public Partial classForm1:form -     { the          PublicForm1 () -         { - InitializeComponent (); -  +              This. Printdocument1.originatmargins =true;//Enable page margins -              This. Pagesetupdialog1.enablemetric =true;//in millimeters +         } A  at         /// <summary> -         ///Print -         /// </summary> -         Private voidButton1_Click (Objectsender, EventArgs e) -         { -             if( This. Printdialog1.showdialog () = =DialogResult.OK) in             { -                  This. Printdocument1.print (); to             } +         } -  the         /// <summary> *         ///Print Settings $         /// </summary>Panax Notoginseng         Private voidButton2_Click (Objectsender, EventArgs e) -         { the              This. Pagesetupdialog1.showdialog (); +         } A  the         /// <summary> +         ///Print Preview -         /// </summary> $         Private voidButton3_Click (Objectsender, EventArgs e) $         { -              This. Printpreviewdialog1.showdialog (); -         } the  -         Private voidPrintdocument1_printpage (Objectsender, System.Drawing.Printing.PrintPageEventArgs e)Wuyi         { the             ////----------------The entire form is printed---------------- -             //Image myformimage; Wu             //myformimage = new Bitmap (this. Width, this. Height); -             //Graphics g = graphics.fromimage (myformimage); About             //G.copyfromscreen (this. Location.x, this. LOCATION.Y, 0, 0, this. Size); $             //e.graphics.drawimage (myformimage, 0, 0); -  -             ////----------------Print content as a local this.groupbox1---- -             //Bitmap _newbitmap = new Bitmap (groupbox1.width, groupbox1.height); A             //Groupbox1.drawtobitmap (_newbitmap, New Rectangle (0, 0, _newbitmap.width, _newbitmap.height)); +             //e.graphics.drawimage (_newbitmap, 0, 0, _newbitmap.width, _newbitmap.height); the  -             //------------------Print content as custom text content------------ $Font font =NewFont ("Song Body", A); theBrush Bru =Brushes.blue; the             //for (int i = 1; I <= 5; i++) the             //{ the                  -             //} inE.graphics.drawstring ("Hello World", Font, BRU,Ten,Ten); the         } the     } About}

Complete.

c#-winform-Print Controls

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.