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

    code:

    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 WindowsTest
    {
        public partial class Form8 : Form
        {
            public Form8()
            {
                InitializeComponent();
                this.printDocument1.OriginAtMargins = true;//启用页边距
                this.pageSetupDialog1.EnableMetric = true; //以毫米为单位
    
            }
    
            private void btnSetPrint_Click(object sender, EventArgs e)
            {//打印设置
                this.pageSetupDialog1.ShowDialog(); 
    
            }
    
            private void btnPrePrint_Click(object sender, EventArgs e)
            { //打印预览
                //指定要打印的文档
                //printPreviewDialog1.Document = printDocument1;
                this.printPreviewDialog1.ShowDialog(); 
    
            }
    
            private void btnPrint_Click(object sender, EventArgs e)
            {//打印
                if (this.printDialog1.ShowDialog() == DialogResult.OK)
                {
                    this.printDocument1.Print();
                }
            }
    
            private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
            {
                //打印内容 为 自定义文本内容 
                Font font = new Font("宋体", 12);
                Brush bru = Brushes.Blue;
                for (int i = 1; i <= 5; i++)
                {
                    e.Graphics.DrawString(lbMsg.Text, font, bru, 0, i * 20);
                }
            }
        }
    }
    
  • 相关阅读:
    scala学习手记7
    scala学习手记6
    scala学习手记5
    scala学习手记4
    scala学习手记3
    scala学习手记2
    Scala学习手记1
    Java实现的一个小说采集程序
    Java的值传递和引用传递
    java 使用反射
  • 原文地址:https://www.cnblogs.com/suntanyong88/p/5844761.html
Copyright © 2011-2022 走看看