首页 > 代码库 > 【2017-5-3】Winform 打印控件

【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);
        }


通过对于事件数据的绘制来制作要打印的内容

 

页面设置

private void toolStripMenuItem1_Click(object sender, EventArgs e)
        {
            pageSetupDialog1.Document = printDocument1;
            DialogResult dr = pageSetupDialog1.ShowDialog();
            if (dr == DialogResult.OK)
            { 
            
            
            }
        }

 

 

打印预览

private void 打印预览VToolStripMenuItem_Click(object sender, EventArgs e)
        {
            printPreviewControl1.Document = printDocument1;



            printPreviewDialog1.Document = printDocument1;
            DialogResult dr= printPreviewDialog1.ShowDialog();
            if (dr == DialogResult.OK)
            { 
            
            }

        }

 

 

 

打印

注意事件的委托

printPage

private void 打印PToolStripMenuItem_Click(object sender, EventArgs e)
        {
            printDialog1.Document = printDocument1;

           DialogResult dr= printDialog1.ShowDialog();
           if (dr == DialogResult.OK)
           {
               printDocument1.Print();
           
           }

        }

 

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