C# winform 打印事例

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

namespace Zsh.print
{
    public partial class frmBadHzd : Form
    {
        public frmBadHzd()
        {
            InitializeComponent();
        }

        private void frmBadHzd_Paint(object sender, PaintEventArgs e)
        {
            Font font;
            string str;
            float xPos;       //x点坐标
             float yPos;       //y点的坐标
             float topMargin = 0;
            float leftMargin = 0;

            font = new Font("宋体", 12);
            str = "欢迎光临";
            xPos = leftMargin + 15;
            yPos = topMargin;
            e.Graphics.DrawString(str, font, Brushes.Black, xPos, yPos, new StringFormat());

            xPos = leftMargin;
            yPos = yPos + font.GetHeight(e.Graphics) + 5;
            font = new Font("黑体", 12);
            str = "---------------------------------";
            e.Graphics.DrawString(str, font, Brushes.Black, xPos, yPos, new StringFormat());

            xPos = leftMargin + 25;
            yPos = yPos + font.GetHeight(e.Graphics) + 3;
            font = new Font("黑体", 18);
            str = "客 户 回 执 单";
            e.Graphics.DrawString(str, font, Brushes.Black, xPos, yPos, new StringFormat());

            xPos = leftMargin;
            yPos = yPos + font.GetHeight(e.Graphics) + 3;
            font = new Font("黑体", 12);
            str = "---------------------------------";
            e.Graphics.DrawString(str, font, Brushes.Black, xPos, yPos, new StringFormat());

            xPos = leftMargin;
            yPos = yPos + font.GetHeight(e.Graphics) + 5;
            font = new Font("宋体", 11);
            str = "  凭单号";
            e.Graphics.DrawString(str, font, Brushes.Black, xPos, yPos, new StringFormat());

            xPos = leftMargin;
            yPos = yPos + font.GetHeight(e.Graphics) + 5;
            font = new Font("宋体", 11);
            str = "业务类型";
            e.Graphics.DrawString(str, font, Brushes.Black, xPos, yPos, new StringFormat());

            xPos = leftMargin;
            yPos = yPos + font.GetHeight(e.Graphics) + 5;
            font = new Font("宋体", 11);
            str = "    卡号";
            e.Graphics.DrawString(str, font, Brushes.Black, xPos, yPos, new StringFormat());

            xPos = leftMargin;
            yPos = yPos + font.GetHeight(e.Graphics) + 10;
            font = new Font("宋体", 11);
            str = "  原余额";
            e.Graphics.DrawString(str, font, Brushes.Black, xPos, yPos, new StringFormat());

            xPos = leftMargin;
            yPos = yPos + font.GetHeight(e.Graphics) + 5;
            font = new Font("宋体", 11);
            str = "  现余额";
            e.Graphics.DrawString(str, font, Brushes.Black, xPos, yPos, new StringFormat());

            xPos = leftMargin;
            yPos = yPos + font.GetHeight(e.Graphics) + 5;
            font = new Font("黑体", 12);
            str = "---------------------------------";
            e.Graphics.DrawString(str, font, Brushes.Black, xPos, yPos, new StringFormat());

            xPos = leftMargin + 50;
            yPos = yPos + font.GetHeight(e.Graphics) + 5;
            font = new Font("宋体", 14);
            str = "客户签名";
            e.Graphics.DrawString(str, font, Brushes.Black, xPos, yPos, new StringFormat());

            xPos = leftMargin + 130;
            yPos = yPos + font.GetHeight(e.Graphics) - 5;
            font = new Font("宋体", 12);
            str = "-----------";
            e.Graphics.DrawString(str, font, Brushes.Black, xPos, yPos, new StringFormat());

            xPos = leftMargin;
            yPos = yPos + font.GetHeight(e.Graphics);
            font = new Font("宋体", 10);
            str = "受理单位名称";
            e.Graphics.DrawString(str, font, Brushes.Black, xPos, yPos, new StringFormat());

            xPos = leftMargin;
            yPos = yPos + font.GetHeight(e.Graphics) + 5;
            font = new Font("宋体", 10);
            str = "  操作员名称";
            e.Graphics.DrawString(str, font, Brushes.Black, xPos, yPos, new StringFormat());

            xPos = leftMargin + 10;
            yPos = yPos + font.GetHeight(e.Graphics) + 5;
            font = new Font("宋体", 10);
            str = "   日期";
            e.Graphics.DrawString(str, font, Brushes.Black, xPos, yPos, new StringFormat());

            xPos = leftMargin;
            yPos = yPos + font.GetHeight(e.Graphics) + 5;
            font = new Font("黑体", 12);
            str = "---------------------------------";
            e.Graphics.DrawString(str, font, Brushes.Black, xPos, yPos, new StringFormat());

            xPos = leftMargin;
            yPos = yPos + font.GetHeight(e.Graphics) + 5;
            font = new Font("华文行楷", 12);
            str = "此凭单为购物凭证,请妥善保管!";
            e.Graphics.DrawString(str, font, Brushes.Black, xPos, yPos, new StringFormat());
        }

        private void printDocument1_PrintPage(object sender, PrintPageEventArgs e)
        {
            Font font;
            string str;
            float xPos;       //x点坐标
             float yPos;       //y点的坐标
             float topMargin = 0;
            float leftMargin = 0;

            font = new Font("宋体", 12);
            str = "欢迎光临";
            xPos = leftMargin + 15;
            yPos = topMargin;
            e.Graphics.DrawString(str, font, Brushes.Black, xPos, yPos, new StringFormat());

            xPos = leftMargin;
            yPos = yPos + font.GetHeight(e.Graphics) + 5;
            font = new Font("黑体", 12);
            str = "---------------------------------";
            e.Graphics.DrawString(str, font, Brushes.Black, xPos, yPos, new StringFormat());

            xPos = leftMargin + 25;
            yPos = yPos + font.GetHeight(e.Graphics) + 3;
            font = new Font("黑体", 18);
            str = "客 户 回 执 单";
            e.Graphics.DrawString(str, font, Brushes.Black, xPos, yPos, new StringFormat());

            xPos = leftMargin;
            yPos = yPos + font.GetHeight(e.Graphics) + 3;
            font = new Font("黑体", 12);
            str = "---------------------------------";
            e.Graphics.DrawString(str, font, Brushes.Black, xPos, yPos, new StringFormat());

            xPos = leftMargin;
            yPos = yPos + font.GetHeight(e.Graphics) + 5;
            font = new Font("宋体", 11);
            str = "  凭单号";
            e.Graphics.DrawString(str, font, Brushes.Black, xPos, yPos, new StringFormat());

            xPos = leftMargin;
            yPos = yPos + font.GetHeight(e.Graphics) + 5;
            font = new Font("宋体", 11);
            str = "业务类型";
            e.Graphics.DrawString(str, font, Brushes.Black, xPos, yPos, new StringFormat());

            xPos = leftMargin;
            yPos = yPos + font.GetHeight(e.Graphics) + 5;
            font = new Font("宋体", 11);
            str = "    卡号";
            e.Graphics.DrawString(str, font, Brushes.Black, xPos, yPos, new StringFormat());

            xPos = leftMargin;
            yPos = yPos + font.GetHeight(e.Graphics) + 10;
            font = new Font("宋体", 11);
            str = "  原余额";
            e.Graphics.DrawString(str, font, Brushes.Black, xPos, yPos, new StringFormat());

            xPos = leftMargin;
            yPos = yPos + font.GetHeight(e.Graphics) + 5;
            font = new Font("宋体", 11);
            str = "  现余额";
            e.Graphics.DrawString(str, font, Brushes.Black, xPos, yPos, new StringFormat());

            xPos = leftMargin;
            yPos = yPos + font.GetHeight(e.Graphics) + 5;
            font = new Font("黑体", 12);
            str = "---------------------------------";
            e.Graphics.DrawString(str, font, Brushes.Black, xPos, yPos, new StringFormat());

            xPos = leftMargin + 50;
            yPos = yPos + font.GetHeight(e.Graphics) + 5;
            font = new Font("宋体", 14);
            str = "客户签名";
            e.Graphics.DrawString(str, font, Brushes.Black, xPos, yPos, new StringFormat());

            xPos = leftMargin + 130;
            yPos = yPos + font.GetHeight(e.Graphics) - 5;
            font = new Font("宋体", 12);
            str = "-----------";
            e.Graphics.DrawString(str, font, Brushes.Black, xPos, yPos, new StringFormat());

            xPos = leftMargin;
            yPos = yPos + font.GetHeight(e.Graphics);
            font = new Font("宋体", 10);
            str = "受理单位名称";
            e.Graphics.DrawString(str, font, Brushes.Black, xPos, yPos, new StringFormat());

            xPos = leftMargin;
            yPos = yPos + font.GetHeight(e.Graphics) + 5;
            font = new Font("宋体", 10);
            str = "  操作员名称";
            e.Graphics.DrawString(str, font, Brushes.Black, xPos, yPos, new StringFormat());

            xPos = leftMargin + 10;
            yPos = yPos + font.GetHeight(e.Graphics) + 5;
            font = new Font("宋体", 10);
            str = "   日期";
            e.Graphics.DrawString(str, font, Brushes.Black, xPos, yPos, new StringFormat());

            xPos = leftMargin;
            yPos = yPos + font.GetHeight(e.Graphics) + 5;
            font = new Font("黑体", 12);
            str = "---------------------------------";
            e.Graphics.DrawString(str, font, Brushes.Black, xPos, yPos, new StringFormat());

            xPos = leftMargin;
            yPos = yPos + font.GetHeight(e.Graphics) + 5;
            font = new Font("华文行楷", 12);
            str = "此凭单为购物凭证,请妥善保管!";
            e.Graphics.DrawString(str, font, Brushes.Black, xPos, yPos, new StringFormat());
        }

        /// <summary>
        /// 打印票据信息
        /// </summary>
        /// <param name="?">打印机名称</param>
        /// <param name="sho_printNum">打印数量</param>
        public void print(string str_Printer, short sho_printNum)
        {
            try
            {
                PrintDocument pd = new PrintDocument();
                pd.PrinterSettings.PrinterName = str_Printer;
                pd.PrinterSettings.Copies = sho_printNum;
                pd.PrintController = new StandardPrintController();
                pd.PrintPage += new PrintPageEventHandler(printDocument1_PrintPage);
                if (pd.PrinterSettings.IsValid)
                {
                    pd.Print();
                }
                else
                {
                    MessageBox.Show("打印机连接错误", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }
        }
    }
}

源码源于 ==》 http://bbs.csdn.net/topics/310215237

时间: 2024-10-18 23:34:43

C# winform 打印事例的相关文章

Winform 打印PDF顺序混乱,获取打印队列

原文:Winform 打印PDF顺序混乱,获取打印队列 工作中PDF打印顺序混乱着实让我疼痛了好久,其实决绝方法非常简单,但没有想到这个点子的时候确实让我走了很多弯路 这里文章写出来并不是为了炫耀什么,只是觉得发现些好东西就分享出来而已,同时也做个记录,方便以后查找 开始正文 既然要解决打印顺序混乱,那么必须先要实现打印PDF功能,实现PDF打印的方法很多,网上随便一搜就可以找到,这里我贴上自己的打印方法,其实也是网上找到的,稍稍做了修改 Process proc = new Process()

6.30 winform 打印

1 using System; 2 using System.Collections.Generic; 3 using System.ComponentModel; 4 using System.Data; 5 using System.Drawing; 6 using System.Linq; 7 using System.Text; 8 using System.Windows.Forms; 9 10 namespace _6._30_下午打印 11 { 12 public partial

winform 打印

pageSetupDialog 打印设置,和对话框控件差不多的套路,把控件拖到窗口中后,会在下方显示, 然后在制作的菜单中找到打印设置,双击进入点击事件写代码 按照之前的套路, DialogResult drr = pageSetupDialog1.ShowDialog(); if (drr == DialogResult.OK) { } 执行的时候会报错,,就是说问题出现在页面设置,document(类似于一个文档的对象) 在打开打印设置的对话框之前要先告诉它要设置的是什么内容,才能让他把页面

【2017-05-03】winform打印控件、事件对象和事件数据、MDI窗体容器

一.打印控件 第一步先把打印对象搞出来. - printDocument    打印对象(将要打印的内容放到该对象里,从该对象里取内容打印) 设置他的PrintPage事件(对于要打印的每一页触发一次) - pageSetupDialog 打印设置对话框 - printPreviewDialog 打印预览对话框 - printPreviewControl  打印预览控件. 只需要把预览对象给他设置上就好 - printDialog  打印对话框 打印界面里面是否禁用页面范围.打印到文件等从Pri

winform 打印控件

(1)PageSetupDialog1    打印设置窗口  (2)PrintDocument     向打印机输送的对象 事件:PrintPage   对于打印的每一页都执行一次 (3)PrintPreviewControl     打印预览,在本窗口中预览,不包含任何对话框和按钮 (4)PrintPreviewDialog     打印预览,弹出一个预览窗口 (5)PrintDialog     打印   弹出打印窗口可选择打印机和任何打印项设置 //对于打印的每一页都执行一次 privat

winform 打印小票

后台代码 1 panPrintContent.Visible = true; 2 var strlPrinterMode = ""; 3 4 this.pageSetupDialog1.PageSettings.Margins.Left = 1; 5 this.pageSetupDialog1.PageSettings.Margins.Top = 1; 6 this.pageSetupDialog1.PageSettings.Margins.Right = 21; 7 this.pag

C# winform打印总结 z

http://blog.csdn.net/jing_xin/article/details/41444063 针对BEIYANG收据打印机 BTP-R580测试通过. 操作说明:http://www.docin.com/p-395110672.html 1.一般的打印 static Font printFont; //打印使用的字体         public static void PrintEventPage(object sender, PrintPageEventArgs e)    

【2017-5-3】Winform 打印控件

打印控件:要打印,第一步先要想到制作打印对象 private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e) { Font f = new Font("黑体",20); Brush b = new SolidBrush(Color.Red); e.Graphics.DrawString(textBox1.Text, f, b, 20, 50); } 通过

Winform 打印面单

private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e) { Bitmap bit = new Bitmap(this.Width, this.Height); this.MdPanel.DrawToBitmap(bit, new Rectangle(0, 0, this.Width, this.Height)); e.Graphics.DrawImage(