c# 如何打印panel里的内容?
如题能把打印原理讲一遍吗?当前上下文不存在名称BitBltprint_imageprintDocument1...
如题
能把打印原理讲一遍吗?
当前上下文不存在名称 BitBlt print_image printDocument1 展开
能把打印原理讲一遍吗?
当前上下文不存在名称 BitBlt print_image printDocument1 展开
3个回答
展开全部
private void btnPrint_Click(object sender, System.EventArgs e)
{
Graphics graphic = panelReports.CreateGraphics();
Size s = panelReports.Size;
Bitmap memImage = new Bitmap(s.Width, s.Height, graphic);
Graphics memGraphic = Graphics.FromImage(memImage);
IntPtr dc1 = graphic.GetHdc();
IntPtr dc2 = memGraphic.GetHdc();
BitBlt(dc2, 0, 0, panelReports.ClientRectangle.Width, panelReports.ClientRectangle.Height,
dc1, 0, 0, 13369376);
//Clone the bitmap so we can dispose it.
print_image = (Image)memImage.Clone();
graphic.ReleaseHdc(dc1);
memGraphic.ReleaseHdc(dc2);
graphic.Dispose();
memGraphic.Dispose();
memImage.Dispose();
PrintPreviewDialog dlg = new PrintPreviewDialog() ;
dlg.Width = 800;
dlg.Height = 600;
dlg.Document = printDocument1;
if (dlg.ShowDialog() == DialogResult.OK)
printDocument1.Print();
}
panelReports是panel的name
{
Graphics graphic = panelReports.CreateGraphics();
Size s = panelReports.Size;
Bitmap memImage = new Bitmap(s.Width, s.Height, graphic);
Graphics memGraphic = Graphics.FromImage(memImage);
IntPtr dc1 = graphic.GetHdc();
IntPtr dc2 = memGraphic.GetHdc();
BitBlt(dc2, 0, 0, panelReports.ClientRectangle.Width, panelReports.ClientRectangle.Height,
dc1, 0, 0, 13369376);
//Clone the bitmap so we can dispose it.
print_image = (Image)memImage.Clone();
graphic.ReleaseHdc(dc1);
memGraphic.ReleaseHdc(dc2);
graphic.Dispose();
memGraphic.Dispose();
memImage.Dispose();
PrintPreviewDialog dlg = new PrintPreviewDialog() ;
dlg.Width = 800;
dlg.Height = 600;
dlg.Document = printDocument1;
if (dlg.ShowDialog() == DialogResult.OK)
printDocument1.Print();
}
panelReports是panel的name
展开全部
//panel1中包含的图片都必须存在,如果是动态添加的就要保存成数据流来显示,显示后不要释放。或定义PictureBox
Image的显示文件路径
//以panel1为新图象大小设定图片的宽高和其它参数,System.Drawing.Imaging.PixelFormat中还有像素,Alpha等,根据需要自己定义
Bitmap
bmp
=
new
Bitmap(panel1.Width,
panel1.Height,
System.Drawing.Imaging.PixelFormat.Format24bppRgb);
//新建绘制到bmp
Graphics
g
=
Graphics.FromImage(bmp);
g.Clear(Color.White);//上底色
foreach
(PictureBox
pb
in
panel1.Controls)
{
//绘制包含的图象
g
=
Graphics.FromImage(pb.Image);
g.DrawImage(bmp,
pb.Location.X,
pb.Location.Y);
}
//panel1外的pictureBox输出,要保存写成bmp.Save(路径,格式);
this.pictureBox3.Image
=
(Image)bmp;
g.Dispose();
Image的显示文件路径
//以panel1为新图象大小设定图片的宽高和其它参数,System.Drawing.Imaging.PixelFormat中还有像素,Alpha等,根据需要自己定义
Bitmap
bmp
=
new
Bitmap(panel1.Width,
panel1.Height,
System.Drawing.Imaging.PixelFormat.Format24bppRgb);
//新建绘制到bmp
Graphics
g
=
Graphics.FromImage(bmp);
g.Clear(Color.White);//上底色
foreach
(PictureBox
pb
in
panel1.Controls)
{
//绘制包含的图象
g
=
Graphics.FromImage(pb.Image);
g.DrawImage(bmp,
pb.Location.X,
pb.Location.Y);
}
//panel1外的pictureBox输出,要保存写成bmp.Save(路径,格式);
this.pictureBox3.Image
=
(Image)bmp;
g.Dispose();
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
我也遇到了同样的问题。。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询