zoukankan      html  css  js  c++  java
  • winform 打印

    1 新建项目(窗体)

    2 在窗体上添加printDocument 控件 添加 Button textBox 控件

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;

    namespace WindowsFormsApplication1
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }

            private void button1_Click(object sender, EventArgs e)
            {
                PrintDialog printDialog1 = new PrintDialog(); // 声明定义 打印对话框
                printDialog1.Document = printDocument1;
                DialogResult result = printDialog1.ShowDialog();//弹出列印界面
                if (result == DialogResult.OK)
                {
                    //Print()方法打印內容,在打印之前,此方法會在PrntController類的幫助下先呼叫PrintPage事件的方法
                    printDocument1.Print();
                }
            }
            /// <summary>
            
    /// 绘制打印文本,用於得到打印內容
            
    /// </summary>
            
    /// <param name="sender"></param>
            
    /// <param name="e"></param>
            private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
            {
                //textBox1 是打印的文本内容 
                
    //Arial 指定打印字体 20  指定打印字体大小 150, 125 指定在页面中的打印位置
                e.Graphics.DrawString(textBox1.Text, new Font("Arial"20, FontStyle.Bold), Brushes.Black, 150125);
            }
            /// <summary>
            
    /// 打印结束后输出提示文字
            
    /// </summary>
            
    /// <param name="sender"></param>
            
    /// <param name="e"></param>
            private void printDocument1_EndPrint(object sender, System.Drawing.Printing.PrintEventArgs e)
            {
                label1.Text = "打印完毕";
            }
        }
    }
  • 相关阅读:
    Chamfer Distance--倒角距离
    javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure
    mysql单个索引和联合索引的区别
    鸽一下
    笔记:关于 INT1 INT0 中断说明记录 (2020-07-16)[85.22%]
    使用 Git 管理 KiCad EDA 项目文件 [2020-06-28][26.77%]
    从单片机基础到程序框架 2019版(2020-07-04)[12.66%]
    KiCad Pcbnew 中现代工具箱 (2020-06-24)[98.33%]
    【营养研究一】鸡蛋和牛奶的营养对比 (2020-06-23)[95.89%]
    git 忽略上传指定文件 命令
  • 原文地址:https://www.cnblogs.com/Snowfun/p/2854926.html
Copyright © 2011-2022 走看看