</h1>
<div class="clear"></div>
<div class="postBody">
打印控件
绘制如下窗体
一、PrintDocument -打印的基础 首先放置PrintDocument控件,双击事件PrintPage设置要打印的样式(李献策lxc)


//第一步 设置打印属性 private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e) { //设置字体样式 Font f = new System.Drawing.Font("微软雅黑", 16); f = richTextBox1.Font; //设置字体颜色 Brush b = new SolidBrush(richTextBox1.ForeColor);</span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">e.绘制.画字符串(要打印的文本,文本格式,画刷-颜色和纹理,位置坐标)</span> e.Graphics.DrawString(richTextBox1.Text, f, b, <span style="color: rgba(128, 0, 128, 1)">20</span>, <span style="color: rgba(128, 0, 128, 1)">10</span><span style="color: rgba(0, 0, 0, 1)">); } </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">字体样式设置</span> <span style="color: rgba(0, 0, 255, 1)">private</span> <span style="color: rgba(0, 0, 255, 1)">void</span> button4_Click(<span style="color: rgba(0, 0, 255, 1)">object</span><span style="color: rgba(0, 0, 0, 1)"> sender, EventArgs e) { DialogResult dr </span>=<span style="color: rgba(0, 0, 0, 1)"> fontDialog1.ShowDialog(); </span><span style="color: rgba(0, 0, 255, 1)">if</span> (dr ==<span style="color: rgba(0, 0, 0, 1)"> DialogResult.OK) { richTextBox1.Font </span>=<span style="color: rgba(0, 0, 0, 1)"> fontDialog1.Font; richTextBox1.ForeColor </span>=<span style="color: rgba(0, 0, 0, 1)"> fontDialog1.Color; } }</span></pre>
设置Document
二、PageSetupDialog – 打印页面设置


//第二步 设置打印页面设置 private void button1_Click(object sender, EventArgs e) { pageSetupDialog1.Document = printDocument1; pageSetupDialog1.ShowDialog(); }
打印页面设置
三、1、PrintPreviewContol – 打印预览格式一,在窗体中设置预览区域


//第三步 打印预览一 private void button2_Click(object sender, EventArgs e) { printPreviewControl1.Document = printDocument1; }
打印预览一
2、PrintPreviewDialog – 打印预览格式二,在弹窗中预览


//第三步 打印预览二 private void button2_Click(object sender, EventArgs e) { printPreviewDialog1.Document = printDocument1; printPreviewDialog1.ShowDialog(); }
打印预览二
四、PrintDialog – 开始打印


//第四步 开始打印 private void button3_Click(object sender, EventArgs e) { printDialog1.Document = printDocument1; DialogResult dr = printDialog1.ShowDialog(); if (dr == DialogResult.OK) { printDocument1.Print(); } }
开始打印