Form1.cs
上传用户:w139379
上传日期:2022-08-09
资源大小:21k
文件大小:2k
源码类别:

打印编程

开发平台:

JavaScript

  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Text;
  7. using System.Windows.Forms;
  8. //Download by http://www.codefans.net
  9. namespace printout
  10. {
  11.     public partial class Form1 : Form
  12.     {
  13.         public Form1()
  14.         {
  15.             InitializeComponent();
  16.         }
  17.         private void Form1_Load(object sender, EventArgs e)
  18.         {
  19.             printPreviewDialog1.Document = printDocument1;
  20.             printDialog1.Document = printDocument1;
  21.             pageSetupDialog1.Document = printDocument1;
  22.             txtInput.Multiline = true;
  23.             txtInput.ScrollBars = ScrollBars.Both ;
  24.             txtInput.Font=new Font("标准楷体",12,FontStyle.Regular );
  25.         }
  26.         private void btnSetUp_Click(object sender, EventArgs e)
  27.         {
  28.            
  29.             if (pageSetupDialog1.ShowDialog() == DialogResult.OK)
  30.             {
  31.                 printDocument1.DefaultPageSettings = pageSetupDialog1.PageSettings;
  32.             }
  33.         }
  34.         private void btnPreView_Click(object sender, EventArgs e)
  35.         {
  36.             printPreviewDialog1.ShowDialog();
  37.         }
  38.         private void btnPrint_Click(object sender, EventArgs e)
  39.         {
  40.             if (printDialog1.ShowDialog() == DialogResult.OK)
  41.             {
  42.                 printDocument1.Print();
  43.             }
  44.         }
  45.         private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
  46.         {
  47.             Graphics prnGraph = e.Graphics;
  48.             Font prnFont = new Font(txtInput.Font.Name, txtInput.Font.Size, txtInput.Font.Style);
  49.             SolidBrush prnBrush = new SolidBrush(txtInput.ForeColor);
  50.             Single left = printDocument1.DefaultPageSettings.Margins.Left;
  51.             Single top = printDocument1.DefaultPageSettings.Margins.Top ;
  52.             prnGraph.DrawString(txtInput.Text, prnFont, prnBrush, left, top);
  53.         }
  54.         private void btnEnd_Click(object sender, EventArgs e)
  55.         {
  56.             Application.Exit();
  57.         }
  58.         
  59.     }
  60. }