怎样才能打印出Panel中的所有内容,包括Lable和PictureBox控件
下面是我的代码
[System.Runtime.InteropServices.DllImport("gdi32.dll")]
public static extern long BitBlt(IntPtr hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, IntPtr hdcSrc, int nXSrc, int nYSrc, int dwRop);
private Bitmap memImage;
public void Print(object sender,PrintPageEventArgs e)
{
Graphics graphic = framework.pnlframework1.CreateGraphics();
Size s = framework.pnlframework1.Size;
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, framework.pnlframework1.ClientRectangle.Width, framework.pnlframework1.ClientRectangle.Height, dc1, 0, 0, 13369376); //Clone the bitmap so we can dispose it.
Image print_image = (Image)memImage.Clone();
graphic.ReleaseHdc(dc1);
memGraphic.ReleaseHdc(dc2);
memGraphic.Dispose();
memImage.Dispose();
}private void document_PrintPage(object sender, PrintPageEventArgs e)
{
e.Graphics.DrawImage(memImage, 0, 0);
}
出现参数无效,怎样修改?各位高手帮帮忙
下面是我的代码
[System.Runtime.InteropServices.DllImport("gdi32.dll")]
public static extern long BitBlt(IntPtr hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, IntPtr hdcSrc, int nXSrc, int nYSrc, int dwRop);
private Bitmap memImage;
public void Print(object sender,PrintPageEventArgs e)
{
Graphics graphic = framework.pnlframework1.CreateGraphics();
Size s = framework.pnlframework1.Size;
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, framework.pnlframework1.ClientRectangle.Width, framework.pnlframework1.ClientRectangle.Height, dc1, 0, 0, 13369376); //Clone the bitmap so we can dispose it.
Image print_image = (Image)memImage.Clone();
graphic.ReleaseHdc(dc1);
memGraphic.ReleaseHdc(dc2);
memGraphic.Dispose();
memImage.Dispose();
}private void document_PrintPage(object sender, PrintPageEventArgs e)
{
e.Graphics.DrawImage(memImage, 0, 0);
}
出现参数无效,怎样修改?各位高手帮帮忙
解决方案 »
- 蛋疼的下载解压错误,不会整
- 获取计算机的IP地址?
- C#窗体关闭问题...
- DataGridViewComboBoxColumn的问题
- 急问```在线等回`~!
- 试图运行项目时出错:无法在Web服务器上启动调试。未能启动ASP。NET或 ATL Server调试。验证服务器上是否正确安装了ASP。NET或ATL Server
- 参数
- 100分大放送,巨难,毫无头绪,就差重装机器了,快让.net折磨死我了!希望斑竹帮小弟一把!谢谢!
- 如何對DataSet中的table進行類似SQL語句的操作?
- 使用detailsview,自动生成的“编辑”、“更新”、“取消”按钮变成英文
- 帮帮忙帮帮忙
- 求C# 点击按钮实现图片变大。像投票一样的。
Control.DrawToBitmap(参数);然后打印图片可否
外面的用来显示滚动条,里面的用来输出图像和打印
//打印
private void vistaButton1_Click(object sender, EventArgs e)
{
//PrintDocument pd = new PrintDocument();
//pd.PrintPage += new PrintPageEventHandler(pd_PrintPage);
//PrintPreviewDialog cppd = new PrintPreviewDialog();
//cppd.Document = pd;
//cppd.ShowDialog();
Graphics graphic = panel1.CreateGraphics();
Size s = panel1.Size;
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, panel1.ClientRectangle.Width, panel1.ClientRectangle.Height,
dc1, 0, 0, 13369376); //Clone the bitmap so we can dispose it.
Image print_image = (Image)memImage.Clone();
graphic.ReleaseHdc(dc1);
memGraphic.ReleaseHdc(dc2);
graphic.Dispose();
memGraphic.Dispose();
//memImage.Dispose(); PrintPreviewDialog dlg = new PrintPreviewDialog();
dlg.Width = 1100;
dlg.Height = 500;
dlg.Document = printDocument1; if (dlg.ShowDialog() == DialogResult.OK)
printDocument1.Print();
}
//[System.Runtime.InteropServices.DllImport("gdi32.dll ")]
//public static extern long BitBlt(IntPtr hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, IntPtr hdcSrc, int nXSrc, int nYSrc, int dwRop);
//private Bitmap memoryImage;
//private void CaptureScreen()
//{
// Graphics mygraphics = this.panel1.CreateGraphics();//绘制Panel图像
// Size s = this.panel1.Size;//取Panel的大小
// memoryImage = new Bitmap(s.Width, s.Height, mygraphics);
// Graphics memoryGraphics = Graphics.FromImage(memoryImage);
// IntPtr dc1 = mygraphics.GetHdc();
// IntPtr dc2 = memoryGraphics.GetHdc();
// BitBlt(dc2, 0, 0, this.panel1.ClientRectangle.Width, this.panel1.ClientRectangle.Height, dc1, 0, 0, 13369376);
// mygraphics.ReleaseHdc(dc1);
// memoryGraphics.ReleaseHdc(dc2);
//}
[System.Runtime.InteropServices.DllImportAttribute("gdi32.dll")]//应用API函数
private static extern bool BitBlt(
IntPtr hdcDest, // 目标设备的句柄
int nXDest, // 目标对象的左上角的X坐标
int nYDest, // 目标对象的左上角的X坐标
int nWidth, // 目标对象的矩形的宽度
int nHeight, // 目标对象的矩形的长度
IntPtr hdcSrc, // 源设备的句柄
int nXSrc, // 源对象的左上角的X坐标
int nYSrc, // 源对象的左上角的X坐标
System.Int32 dwRop // 光栅的操作值
); void pd_PrintPage(object sender, PrintPageEventArgs e)
{
//Graphics g = e.Graphics;
//BarcodeControl dd = new BarcodeControl(); //Rectangle rect = dd.ClientRectangle;
////打印
//dd.Draw(g, rect, GraphicsUnit.Inch, 0.01f, 0, null);
//g.Dispose();
//只打印图像
e.Graphics.DrawImage(memImage, 0, 0);
}
//预览
int mm;
private void button2_Click(object sender, EventArgs e)
{
#region //打印预览
string sqlstr = "select Count(distinct PartID) from L_Craft where MouldID='" +
txtMid.Text.Trim().ToString() + "'";
int num = MRP.DBHelper.GetScalar(sqlstr); string[] part = new string[num];
////查询零件号
string sql = "select distinct mould_m from L_Craft where MouldID='" +
txtMid.Text.Trim().ToString() + "'"; SqlDataReader reader = MRP.DBHelper.GetReader(sql);
int t = 0;
while (reader.Read())
{
part[t++] = reader[0].ToString();
}
for (int i = 0; i < num; i++)
{
#region 1种方法
BarcodeControl dd = new BarcodeControl();
//dd.Size = new Size(160, 50);
//dd.Location = new Point((i % 3) * 160 + 100, i / 3 * 100);
//dd.CopyRight = "Imold条码"; //标题
dd.Data = part[i]; // 条形码取的数据
dd.BarcodeType=BarcodeType.CODE128B; //条形码类型 dd.Size = new Size(300, 90);
dd.Location = new Point((i % 3) * 280 +50, (i / 3) * 120);
this.panel1.Controls.Add(dd);
#endregion
}
#endregion
}
private void printDocument1_PrintPage(object sender, PrintPageEventArgs e)
{
e.Graphics.DrawImage(memImage,0,0);
}这样打印,打印的只是本页的内容,怎么才能打印全部的呢,就是panel 滚动条下面的数据
这样打印,打印的只是本页的内容,怎么才能打印全部的呢,就是panel 滚动条下面的数据
然后使用Panel1.DrawToBitmap()输出。