zoukankan      html  css  js  c++  java
  • 打印

    下面,来进行简单的winform打印功能的使用:

    页面布局如下:

    代码实现:

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows.Forms;
    
    namespace WindowsForms代码
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
    
            private void Btn_Print_Click(object sender, EventArgs e)
            {
                // 定义打印模板(paper纸张)的大小;Custum表示自定义纸张大小
                this.PD_document.DefaultPageSettings.PaperSize = new System.Drawing.Printing.PaperSize("Custum", 1000, 520);
                this.PD_document.PrintPage += PD_document_PrintPage; // 添加打印事件(快捷键:Tab)
                //this.PPD_Dialog.Document = this.PD_document;  // 预览
                //if(this.PPD_Dialog.ShowDialog()==DialogResult.OK)
                //{
                //    this.PD_document.Print();  // 打印
                //}
                // 使用printDialog(也可以同上PPD_Dialog在页面进行添加)
                PrintDialog printDialog = new PrintDialog();
                printDialog.UseEXDialog = true;  // 弹出打印对话框界面
                if(printDialog.ShowDialog()==DialogResult.OK)
                {
                    this.PD_document.Print();
                }
            }
    
            // 进行画图
            private void PD_document_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
            {
                // 绘制字符串
                e.Graphics.DrawString("PrintString", new Font(new FontFamily("宋体"), 24), System.Drawing.Brushes.Yellow, 20, 20);
            }
        }
    }

    待续。。。

  • 相关阅读:
    java poi 从服务器下载模板写入数据再导出
    一个华为面试题
    ForEach 循环
    fmt标签格式化数字和时间
    Ichars制作数据统计图
    jQuery中的事件
    oracle学习第四天
    GET请求和POST请求
    Jsp的九个隐含对象
    Oracle学习【语句查询】
  • 原文地址:https://www.cnblogs.com/namejr/p/11509091.html
Copyright © 2011-2022 走看看