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 = "打印完毕";
            }
        }
    }
  • 相关阅读:
    OpenStack-Queens版本缓存yum源的问题
    HTML 表单和输入<textarea><label><fieldset><legend><select><optgroup><option><button>
    HTML 表单和输入<form><input>
    HTML 列表 <ol><ul><li><dl><dt><dd>
    HTML 表格<table><caption><th><tr><td><thead><tbody><tfoot><col><colgroup>
    HTML <span> 标签
    HTML <div> 标签
    HTML 教程延伸阅读:改变文本的外观和含义
    引用、引用和术语定义<abbr><acronym><address><bdo><blockquote><q><cite><dfn>
    HTML“计算机输出”标签 <code><kbd><samp><tt><var><pre>
  • 原文地址:https://www.cnblogs.com/Snowfun/p/2854926.html
Copyright © 2011-2022 走看看