嗨,我从MSDN收到这段代码。我找不出问题,希望你能帮上忙。错误的位置是带有单词printForm1的两行。我的表单实际上被称为Form1,所以我看不到问题。
[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.CreateGraphics();
Size s = this.Size;
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.ClientRectangle.Width, this.ClientRectangle.Height, dc1, 0, 0, 13369376);
mygraphics.ReleaseHdc(dc1);
memoryGraphics.ReleaseHdc(dc2);
}
private void printDocument1_PrintPage(System.Object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
e.Graphics.DrawImage(memoryImage, 0, 0);
}
private void btnCreate_Click(object sender, EventArgs e)
{
btncustCont.Visible = false;
btnprintCost.Visible = false;
btnpdfCont.Visible = false;
btnpdfBrochureCont.Visible = false;
btnpaperCont.Visible = false;
btnduplicateCont.Visible = false;
btntypeCont.Visible = false;
btnCalcCost.Visible = false;
btnprintCost.Visible = false;
Application.DoEvents();
CaptureScreen();
printForm1.PrinterSettings.DefaultPageSettings.Landscape = true;
printForm1.Print();
btncustCont.Visible = true;
btnprintCost.Visible = true;
btnpdfCont.Visible = true;
btnpdfBrochureCont.Visible = true;
btnpaperCont.Visible = true;
btnduplicateCont.Visible = true;
btntypeCont.Visible = true;
btnCalcCost.Visible = true;
btnprintCost.Visible = true;
}发布于 2013-08-28 19:37:37
看看这篇MSDN文章是如何在类的顶部声明printDocument1的:
private PrintDocument printDocument1 = new PrintDocument();http://msdn.microsoft.com/en-us/library/vstudio/6he9hz8c(v=vs.100).aspx
你也会想做同样的事,只想用printForm1
发布于 2013-08-28 19:37:21
我能想到两种可能性:
如果我读得对,printForm1是PrintDocument对象的一个实例。对不起,如果我在这里没有给你足够的信用,但你确定printForm1实际上是在任何地方申报的吗?
否则,确保您的(codeBehind).cs文件实际上继承了包含此元素的页面。
https://stackoverflow.com/questions/18496698
复制相似问题