首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

打印整个窗体 但是PictureBox跟LineShape打不出来 请高手赐教

2012-12-15 
打印整个窗体 但是PictureBox和LineShape打不出来请高手赐教!我想打印整个窗体,这个窗体不显示,lable和条

打印整个窗体 但是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.Y, bit.Width, bit.Height);
                }


                else if (c is ShapeContainer)
                {
                    ShapeContainer b = (ShapeContainer)c;
                    foreach (Shape sh in b.Shapes)
                    {
                        if (sh is LineShape)
                        {
                            LineShape lin = (LineShape)sh;
                            Pen mypen = new Pen(lin.BorderColor, lin.BorderWidth);
                            mypen.DashStyle = lin.BorderStyle;
                            e.Graphics.DrawLine(mypen, lin.StartPoint, lin.EndPoint);
                        }
                    }
                }
            }

        }


[解决办法]
null

热点排行