Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to set up C # print to realize the Analysis of Source Code

2025-04-03 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article shows you how to carry out C# print settings to achieve source code analysis, the content is concise and easy to understand, absolutely can make your eyes bright, through the detailed introduction of this article, I hope you can get something.

How is the C# print setting reflected in the actual programming development? What do you need to pay attention to in C# print settings? How do you operate the common properties of C# print settings? Let's solve these problems in an example:

C# print setup example code:

Summary description of the Form1 of using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data; namespace WindowsApplication1 {/ C# print settings. / public class Form1: designer variables required for System.Windows.Forms.Form {private System.Drawing.Printing.PrintDocument pd; private PrintPreviewControl ppc; private PrintPreviewDialog ppd; private System.Windows.Forms.PrintDialog printDialog1; private System.Windows.Forms.Button button1; private System.Windows.Forms.Button button2; private System.Windows.Forms.Button button3; private System.Windows.Forms.TextBox textBox1; String text= "; / C# print settings. / private System.ComponentModel.Container components = null; public Form1 () {/ C# print setup Windows forms designer support required / / InitializeComponent (); / TODO: add any constructor code / /} / C # print setup to clean up all resources in use after the InitializeComponent call. / / protected override void Dispose (bool disposing) {if (disposing) {if (components! = null) {components.Dispose ();}} base.Dispose (disposing);} the code generated by the region Windows forms designer / the designer of the C# print setup supports the required methods-do not modify / the contents of this method using a code editor. / / private void InitializeComponent () {this.pd = new System.Drawing.Printing.PrintDocument (); this.button1 = new System.Windows.Forms.Button (); this.button2 = new System.Windows.Forms.Button (); this.button3 = new System.Windows.Forms.Button (); this.textBox1 = new System.Windows.Forms.TextBox (); this.printDialog1 = new System.Windows.Forms.PrintDialog (); this.SuspendLayout () / button1 / / this.button1.Location = new System.Drawing.Point (32,154); this.button1.Name = "button1"; this.button1.Size = new System.Drawing.Size (75,23); this.button1.TabIndex = 1; this.button1.Text = "start printing"; this.button1.Click + = new System.EventHandler (this.button1_Click); / button2 / / this.button2.Location = new System.Drawing.Point (120,154) This.button2.Name = "button2"; this.button2.Size = new System.Drawing.Size (75,23); this.button2.TabIndex = 2; this.button2.Text = "print Preview"; this.button2.Click + = new System.EventHandler (this.button2_Click); / button3 / / this.button3.Location = new System.Drawing.Point (208,154); this.button3.Name = "button3"; this.button3.Size = new System.Drawing.Size (75,23) This.button3.TabIndex = 3; this.button3.Text = "printer settings"; this.button3.Click + = new System.EventHandler (this.button3_Click); / textBox1 / / this.textBox1.Location = new System.Drawing.Point (16,16); this.textBox1.Multiline = true; this.textBox1.Name = "textBox1"; this.textBox1.ScrollBars = System.Windows.Forms.ScrollBars.Both; this.textBox1.Size = new System.Drawing.Size (270,116) This.textBox1.TabIndex = 4; / Form1 / / this.AutoScaleBaseSize = new System.Drawing.Size (6,14); this.ClientSize = new System.Drawing.Size (314,199); this.Controls.Add (this.textBox1); this.Controls.Add (this.button3); this.Controls.Add (this.button2); this.Controls.Add (this.button1); this.Name = "Form1"; this.Text = "print form" This.Load + = new System.EventHandler (this.Form1_Load); this.ResumeLayout (false); this.PerformLayout (); main entry point of the application for print settings} # endregion / C#. / / [STAThread] static void Main () {Application.Run (new Form1 ());} private void Form1_Load (object sender, System.EventArgs e) {/ / C# print setup creation instance this.pd=new System.Drawing.Printing.PrintDocument (); this.ppc=new PrintPreviewControl (); this.ppd=new PrintPreviewDialog (); this.printDialog1=new PrintDialog () / / trigger event this.pd.BeginPrint+=new System.Drawing.Printing.PrintEventHandler (pd_BeginPrint) for C# print settings; this.pd.PrintPage+=new System.Drawing.Printing.PrintPageEventHandler (pd_PrintPage);} private void pd_BeginPrint (object sender, System.Drawing.Printing.PrintEventArgs e) {/ / C# print settings horizontal printing this.pd.DefaultPageSettings.Landscape=true; / / C# printing settings color printing this.pd.DefaultPageSettings.Color=true / / setting of the C# print setup print paper type and size this.pd.DefaultPageSettings.PaperSize= new System.Drawing.Printing.PaperSize ("A4", 800jue 1100);} private void pd_PrintPage (object sender, System.Drawing.Printing.PrintPageEventArgs e) {/ / C# the content of the text box of the print setup is transferred to the printer print text=this.textBox1.Text E.Graphics.DrawString (text, new Font ("Arial", 30, FontStyle.Regular), Brushes.Black, 0,0);} private void button1_Click (object sender, System.EventArgs e) {/ / C# print setup start print this.pd.Print ();} private void button2_Click (object sender, System.EventArgs e) {/ / C# print setup print preview information ppc.Document=pd; ppc.Columns=2 Display preview of ppc.Rows=2; ppc.Zoom=0.5; ppc.StartPage=1; / / C# print settings ppd.Document=pd; try {ppd.ShowDialog ();} catch (Exception excep) {MessageBox.Show (excep.Message, "print error", MessageBoxButtons.OK, MessageBoxIcon.Error) }} private void button3_Click (object sender, System.EventArgs e) {/ / C # printer settings this.printDialog1.Document=pd; this.printDialog1.AllowSomePages=true; this.printDialog1.PrintToFile=false; / / C # print settings determine printer information and start printing if (this.printDialog1.ShowDialog () = = DialogResult.OK) {try {this.pd.Print () } catch (Exception excep) {MessageBox.Show (excep.Message, "print error", MessageBoxButtons.OK, MessageBoxIcon.Error);}

C# print settings related examples and introduction to you here, a lot of specific operations are reflected in the notes, I hope it will help you to understand and learn C# print settings.

The above content is how to analyze the source code of C# print setup. Have you learned the knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report