Form1.cs
资源名称:dayinji.rar [点击查看]
上传用户:w139379
上传日期:2022-08-09
资源大小:21k
文件大小:2k
源码类别:
打印编程
开发平台:
JavaScript
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Text;
- using System.Windows.Forms;
- //Download by http://www.codefans.net
- namespace printout
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
- private void Form1_Load(object sender, EventArgs e)
- {
- printPreviewDialog1.Document = printDocument1;
- printDialog1.Document = printDocument1;
- pageSetupDialog1.Document = printDocument1;
- txtInput.Multiline = true;
- txtInput.ScrollBars = ScrollBars.Both ;
- txtInput.Font=new Font("标准楷体",12,FontStyle.Regular );
- }
- private void btnSetUp_Click(object sender, EventArgs e)
- {
- if (pageSetupDialog1.ShowDialog() == DialogResult.OK)
- {
- printDocument1.DefaultPageSettings = pageSetupDialog1.PageSettings;
- }
- }
- private void btnPreView_Click(object sender, EventArgs e)
- {
- printPreviewDialog1.ShowDialog();
- }
- private void btnPrint_Click(object sender, EventArgs e)
- {
- if (printDialog1.ShowDialog() == DialogResult.OK)
- {
- printDocument1.Print();
- }
- }
- private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
- {
- Graphics prnGraph = e.Graphics;
- Font prnFont = new Font(txtInput.Font.Name, txtInput.Font.Size, txtInput.Font.Style);
- SolidBrush prnBrush = new SolidBrush(txtInput.ForeColor);
- Single left = printDocument1.DefaultPageSettings.Margins.Left;
- Single top = printDocument1.DefaultPageSettings.Margins.Top ;
- prnGraph.DrawString(txtInput.Text, prnFont, prnBrush, left, top);
- }
- private void btnEnd_Click(object sender, EventArgs e)
- {
- Application.Exit();
- }
- }
- }