C#中打印窗体时,如何不弹出显示正在打印的小对话框?

jgbeaver 2003-09-13 03:45:43
我用下面的方法打印窗体
但是把小框子也打出来了,遮住了窗体

1. Add a print function to your application.



To do this, you should add a PrintDocument component to your application.

Please drag a PrintDocument from the tool box to your form. After that, you

should create a PrintDialog and add the code to print the document.



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();

}

}



For detailed information about print framework, please see "Windows Forms

Print Support" in the MSDN (October 2001).



2. Draw the form when printing.



This step is a little complex. You should handle the PrintPage of the

printDocument1 and draw the form to the printer device. In the event you

may copy the form to an image and then draw it to the printer device.



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);

}



The above referenced the article "Screen Capturing a Form in .NET - Using

GDI in GDI+" by Michael Gold. You may find it at:

http://www.c-sharpcorner.com/Graphics/ScreenCaptFormMG.asp



3. Declare the API function.



Please note the BitBlt function used in Step 2. It is an unmanaged

function. You should use DllImportAttribute attribute to import it to your

code. Although, this is the Step 3, you may perform this step any time.



[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

);


...全文
639 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
jgbeaver 2003-09-13
  • 打赏
  • 举报
回复
老大搞定了
原来这么简单
放到最前面就行了
没想到啊
谢谢!
给分!!!
cnhgj 2003-09-13
  • 打赏
  • 举报
回复
小窗体是还会出现,但是不知道能不能不让它挡住!
jgbeaver 2003-09-13
  • 打赏
  • 举报
回复
先谢谢你
我试一试
cnhgj 2003-09-13
  • 打赏
  • 举报
回复
form.topmost=true试试,我没有打印机,没法试
cnhgj 2003-09-13
  • 打赏
  • 举报
回复
将form1.topmost设为true试试,我这里没打印机
jgbeaver 2003-09-13
  • 打赏
  • 举报
回复
我打印了好多次了,还是没搞定
jgbeaver 2003-09-13
  • 打赏
  • 举报
回复
大家快来帮帮我呀!
cnhgj 2003-09-13
  • 打赏
  • 举报
回复
研究中~!!
jgbeaver 2003-09-13
  • 打赏
  • 举报
回复
有人帮忙吗?
我在线等。
jgbeaver 2003-09-13
  • 打赏
  • 举报
回复
是自动消失了
但是我打印出来的时候为什么上面有那个小窗体呢
他是截取的时候把这个也截下来了。

这个窗体只是一闪就过了,但还是一起打出来了。
cnhgj 2003-09-13
  • 打赏
  • 举报
回复
你是不是想去掉进度窗体啊?打印内容装入打印机后那个窗体会自动消失的
jgbeaver 2003-09-13
  • 打赏
  • 举报
回复
有人帮忙吗?
jgbeaver 2003-09-13
  • 打赏
  • 举报
回复

PrintDialog printDialog1 = new PrintDialog();

printDialog1.Document = printDocument1;

DialogResult result = printDialog1.ShowDialog();

if (result == DialogResult.OK)

{
}

我将这几行代码注销了,它 不在显示,打印设计的对话框了,
但是还是要跳出正在打印的那个小框。
使得打印结果被小框遮掉了一部分
这个问题怎么解决呢?

110,561

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧