日期:2014-05-17  浏览次数:21018 次

打印整个窗体 但是PictureBox和LineShape打不出来 请高手赐教!
我想打印整个窗体,这个窗体不显示,lable和条码控件能打出来  但是PictureBox和LineShape(VB里的画线)打出来空白的,小弟新手,请高手帮帮忙
我用的打印方法:

private void pd_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
    Bitmap bit = new Bitmap(frm.Width, frm.Height);
    frm.DrawToBitmap(bit, new Rectangle(0, 0, frm.Width, frm.Height));
    bit.Save("D://AAA.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
    e.Graphics.DrawImage(bit, 0, 0, bit.Width, bit.Height);
    bit.Dispose();
}

------解决方案--------------------
自己搞定了

        private void pd_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
        {
            foreach (Control c in frm.Controls)
            {
                if (c is UserLable)
                {
                    e.Graphics.DrawString(c.Text, c.Font,
                         new SolidBrush(c.ForeColor), c.Location);
                }
                else if (c is PictureBox)
                {
                    PictureBox b = (PictureBox)c;
                    e.Graphics.DrawImage(b.Image, c.Location.X,
                         c.Location.Y, c.Width, c.Height);
                }
                else if (c is BarcodeControl)
                {
                    BarcodeControl b = (BarcodeControl)c;
                    Bitmap bit = new Bitmap(b.Width, b.Height);
                    b.DrawToBitmap(bit, new Rectangle(0, 0, b.Width, b.Height));
                    e.Graphics.DrawImage(bit, b.Location.X,b.Location.