收据打印窗体

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;
using System.Drawing.Printing;


namespace aa
{
    public partial class from1 : Form
    {
        public from1()
        {
            InitializeComponent();
            this.printDocument1.OriginAtMargins = true;//启用页边距
        }


        //打印
        private void button1_Click(object sender, EventArgs e)
        {


            this.printPreviewDialog1.ShowDialog();
        }
        //打印预览
        private void button2_Click(object sender, EventArgs e)
        {
            if (this.printDialog1.ShowDialog() == DialogResult.OK)
            {
                this.printDocument1.Print();
            }
        }


        private void printDocument1_PrintPage_1(object sender, PrintPageEventArgs e)
        {


            //打印内容 为 局部的 this.groupBox1
            Bitmap _NewBitmap = new Bitmap(groupBox1.Width, groupBox1.Height);
            groupBox1.DrawToBitmap(_NewBitmap, new Rectangle(0, 0, _NewBitmap.Width, _NewBitmap.Height));
            e.Graphics.DrawImage(_NewBitmap, 0, 0, _NewBitmap.Width, _NewBitmap.Height);


        }
        //打印设置
        private void button3_Click(object sender, EventArgs e)
        {
            this.pageSetupDialog1.ShowDialog();
        }


        private void button4_Click(object sender, EventArgs e)
        {
            this.Close();
        }


    }
}


你可能感兴趣的:(打印,收据)