闪电龟龟--笔记

万物寻其根,通其堵,便能解其困。
随笔 - 169, 文章 - 0, 评论 - 1, 阅读 - 79596
  博客园  :: 新随笔  :: 管理

打印

Posted on   闪电龟龟  阅读(235)  评论(0编辑  收藏  举报

下面,来进行简单的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);
        }
    }
}
复制代码

 

待续。。。

编辑推荐:
· AI与.NET技术实操系列:基于图像分类模型对图像进行分类
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
阅读排行:
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 25岁的心里话
· 按钮权限的设计及实现
点击右上角即可分享
微信分享提示