用printer控件,GDI+画上想要打印的内容

解决方案 »

  1.   

    参考
            private void button2_Click(object sender, EventArgs e)
            {
                PrintDocument pd = new PrintDocument();
                pd.PrintPage += new PrintPageEventHandler(this.printDocument1_PrintPage);
                StandardPrintController spc = new StandardPrintController();
                pd.PrintController = spc;
                pd.PrinterSettings.PrinterName = "发送至 OneNote 2010";
                pd.Print();
             
            }        private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
            {
                e.Graphics.PageUnit = GraphicsUnit.Document;
                e.Graphics.DrawString(this.textBox1.Text, new Font("Arial", 11), new SolidBrush(Color.Black), 100.0F, 5.0F);
                e.Graphics.DrawImage(DrawImg39(new EnCodeString().code39(this.textBox1.Text)), 10.0F, 70.0F);
                e.Graphics.DrawString("test", new Font("Arial", 11), new SolidBrush(Color.Black), 70F, 180.0F);
                e.Graphics.DrawString("test", new Font("Arial", 11), new SolidBrush(Color.Black), 180F, 220.0F);
                PaperSize cps = new PaperSize("Customer", 30, 30);
                e.PageSettings.PaperSize = cps;
                e.PageSettings.PaperSize.PaperName = "4xe Enhanced";
                e.HasMorePages = false;
            }
      

  2.   

        pd.PrinterSettings.PrinterName = "发送至 OneNote 2010"; 
    这里不是写的打印机么?
    如果不写这句就是用默认打印机,如果要选打印机,那你自己加一个PrintDialog
      

  3.   

    WebBrowser组件execWB方法进行打印示例
    //打印页面设置
    <form id="form1" runat="server">
        <div>
         <table>
                    <tr>
                        <td style="width: 466px;  text-align: center;">
                            <asp:Label ID="Label1" runat="server" Font-Size="12pt" Font-Bold="True" ></asp:Label>
                          </td></tr>
                        <tr><td style="font-size: 9pt; width: 466px; text-indent: 8pt; text-align: left; height: 380px;">
                            <asp:Label ID="Label2" runat="server" Font-Size="9pt" Height="412px" 
                                Width="430px"  BorderWidth="1px" ForeColor="#404040"></asp:Label>
                          </td>
                    </tr>
                    <tr>
                        <td style="text-align: center; width: 466px; height: 46px;">
                    <object id="WebBrowser" height="0" width="0" classid="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2">
                    </object>
                    <asp:Panel ID="panel1" runat="server" Width="460px" Height="12px">
                    <input onclick="document.all.WebBrowser.ExecWB(6,1);" type="button" value="打印" id="Button1" > 
                    <input onclick="document.all.WebBrowser.ExecWB(6,6);" type="button" value="直接打印"  id="Button2">
                    <input onclick="document.all.WebBrowser.ExecWB(8,1);" type="button" value="页面设置"  id="Button3">
                    <input onclick="document.all.WebBrowser.ExecWB(7,1);" type="button" value="打印预览" id="Button4" >
                    <input type="button" value="关闭窗口" onclick="javascript:window.close()"  id="Button5">
                            </asp:Panel></td>
                    </tr>
                </table>
        </div>
    </form>
    //处理打印设置
    public partial class _Default : System.Web.UI.Page 
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string path = Server.MapPath("App_Data\\jytk.txt");
            System.IO.StreamReader reader = new System.IO.StreamReader(path, System.Text.Encoding.Default);
            this.Label1.Text = reader.ReadLine();
            this.Label2.Text = reader.ReadToEnd();
            reader.Close();
        }
    }
      

  4.   

    reporting service来做,排版容易