在winform使用了窗体背景图片,但打印时不想打印窗体背景图片。如何做?
我目前打印时使用代码大略如下private void buttonPrint_Click(object sender, System.EventArgs e)
{
PrintDialog printDialog1 = new PrintDialog();
printDialog1.Document = printDocument1;
DialogResult result = printDialog1.ShowDialog();
if (result == DialogResult.OK)
{
printDocument1.Print();
}
}
private void printDocument1_PrintPage(object sender,
System.Drawing.Printing.PrintPageEventArgs e)
{
Graphics graphic = this.CreateGraphics();
Size s = this.Size;
Image 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, this.ClientRectangle.Width,
this.ClientRectangle.Height, dc1, 0, 0, 13369376);
graphic.ReleaseHdc(dc1);
memGraphic.ReleaseHdc(dc2);
e.Graphics.DrawImage(memImage,0,0);
}
[System.Runtime.InteropServices.DllImportAttribute("gdi32.dll")]
private static extern bool BitBlt(
IntPtr hdcDest, // handle to destination DC
int nXDest, // x-coord of destination upper-left corner
int nYDest, // y-coord of destination upper-left corner
int nWidth, // width of destination rectangle
int nHeight, // height of destination rectangle
IntPtr hdcSrc, // handle to source DC
int nXSrc, // x-coordinate of source upper-left corner
int nYSrc, // y-coordinate of source upper-left corner
System.Int32 dwRop // raster operation code
);
我目前打印时使用代码大略如下private void buttonPrint_Click(object sender, System.EventArgs e)
{
PrintDialog printDialog1 = new PrintDialog();
printDialog1.Document = printDocument1;
DialogResult result = printDialog1.ShowDialog();
if (result == DialogResult.OK)
{
printDocument1.Print();
}
}
private void printDocument1_PrintPage(object sender,
System.Drawing.Printing.PrintPageEventArgs e)
{
Graphics graphic = this.CreateGraphics();
Size s = this.Size;
Image 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, this.ClientRectangle.Width,
this.ClientRectangle.Height, dc1, 0, 0, 13369376);
graphic.ReleaseHdc(dc1);
memGraphic.ReleaseHdc(dc2);
e.Graphics.DrawImage(memImage,0,0);
}
[System.Runtime.InteropServices.DllImportAttribute("gdi32.dll")]
private static extern bool BitBlt(
IntPtr hdcDest, // handle to destination DC
int nXDest, // x-coord of destination upper-left corner
int nYDest, // y-coord of destination upper-left corner
int nWidth, // width of destination rectangle
int nHeight, // height of destination rectangle
IntPtr hdcSrc, // handle to source DC
int nXSrc, // x-coordinate of source upper-left corner
int nYSrc, // y-coordinate of source upper-left corner
System.Int32 dwRop // raster operation code
);
解决方案 »
- 结构类型里定义了数组成员,怎么定义数组的大小和赋初始值
- 未将对象引用设置到对象的实例。
- 逐级减现存量
- [道歉帖]上次做错事了 说错话了 道个歉 请个教
- 只有40分可以用了,问几个问题,希望大家能给个正确的答案
- 高分求RichTextBox 的问题,搜索了半天居然没有答案...
- axWindowsMediaPlayer1的问题
- 怎样在WPF中打印日历
- 关于 CSDN的一个bug,可以看到美女,是不是看到了如下内容呢????(不知道各位都看到的什么???)
- 用HashPasswordForStoringInConfigFile方法加密的字符串如何解密?
- 只用一个异步的socket和同时和N个客户收发信息和文件行不?
- static public SqlConnection conn = new SqlConnection(sqlconn);(在线等)
首先,用绘画的方式去画出没有背景的窗体底图,然后分别抓取窗体上的控件,在按照位置进行绘画,最后在打印。我的winform里现在都只是一些text控件但不知道这种怎样做,有代码例子吗?