在窗体中插入了label,textbox,dateTimePicker等控件如何把他们输出到打印机上打印?我是新手希望大家赐教,我目前只是知道调用printDocument控件然后print事件,但是这样出来好像是空白?有待高人解决,在线等!

解决方案 »

  1.   

    你是要打印string类型的值, 还是要把控件截图打印?
    如果是截图打印, Control上有个DrawToBitmap方法。
      

  2.   

    这个需求不是简单调一下printDocument解决的,需要自己处理Print的逻辑,在哪儿画,什么字体,都要自己写
      

  3.   

    类似于报表那样, 你需要控制打印机打印你所需输出的数据.
    具体参考: http://topic.csdn.net/u/20090811/16/429f6dc6-7517-48b9-9e6a-8aaf0c6e2d52.html 之7, 8楼.
      

  4.   

    问题解决了,谢谢大家
     private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
            {
                String biaoti = "通讯产品保修卡";
                String leibie = "产品类别:";
                String leibiet = comboBox1.Text;
                String model  = "产品型号:";
                String modelt = textBox1.Text;
                String sn = "序列号(IMEI):";
                String snt = textBox2.Text;
                String nowtime ="销售时间:";
                String nowtimet = dateTimePicker2.Text;
                String otime ="质保时间至:";
                String otimet = dateTimePicker1.Text;
                String sm = "敬告:凭此保修卡进行质保,丢失、涂";
                String sm2 = "改或污垢不予保修,请妥善保存!";
                Font drawFont = new Font("微软雅黑", 12);
                Font drawFont1 = new Font("微软雅黑", 9);
                Font drawFont2 = new Font("微软雅黑", 8);
                SolidBrush drawBrush = new SolidBrush(Color.Black);
                float x = 20.0F;
                float y = 20.0F;
                StringFormat drawFormat = new StringFormat();
                drawFormat.FormatFlags = StringFormatFlags.NoWrap;
                e.Graphics.DrawString(biaoti, drawFont, drawBrush, x, y, drawFormat);
                e.Graphics.DrawString(leibie, drawFont1, drawBrush, x=0.0f, y=55.0f, drawFormat);
                e.Graphics.DrawString(leibiet, drawFont1, drawBrush, x = 80.0f, y = 55.0f, drawFormat);
                e.Graphics.DrawString(model, drawFont1, drawBrush, x = 0.0f, y = 75.0f, drawFormat);
                e.Graphics.DrawString(modelt, drawFont1, drawBrush, x = 80.0f, y = 75.0f, drawFormat);
                e.Graphics.DrawString(sn, drawFont2, drawBrush, x = 0.0f, y = 95.0f, drawFormat);
                e.Graphics.DrawString(snt, drawFont2, drawBrush, x = 82.0f, y = 95.0f, drawFormat);
                e.Graphics.DrawString(nowtime, drawFont1, drawBrush, x = 0.0f, y = 115.0f, drawFormat);
                e.Graphics.DrawString(nowtimet, drawFont1, drawBrush, x = 60.0f, y = 115.0f, drawFormat);
                e.Graphics.DrawString(otime, drawFont1, drawBrush, x = 0.0f, y = 135.0f, drawFormat);
                e.Graphics.DrawString(otimet, drawFont1, drawBrush, x = 70.0f, y = 135.0f, drawFormat);
                e.Graphics.DrawString(sm, drawFont2, drawBrush, x = 0.0f, y = 195.0f, drawFormat);
                e.Graphics.DrawString(sm2, drawFont2, drawBrush, x = 0.0f, y = 210.0f, drawFormat);
                e.Graphics.DrawImage(pictureBox1.Image,50,153, 80,23); //打印保修凭证章
                e.HasMorePages = false;
                 
                           
            }