问题描述
[System.Runtime.InteropServices.DllImport("gdi32.dll")]publicstaticexternlongBitBlt(IntPtrhdcDest,intnXDest,intnYDest,intnWidth,intnHeight,IntPtrhdcSrc,intnXSrc,intnYSrc,intdwRop);privateBitmapmemoryImage;protectedvoidCaptureScreen(Formform){Graphicsmygraphics=this.CreateGraphics();Sizes=form.Size;memoryImage=newBitmap(s.Width,s.Height,mygraphics);GraphicsmemoryGraphics=Graphics.FromImage(memoryImage);IntPtrdc1=mygraphics.GetHdc();IntPtrdc2=memoryGraphics.GetHdc();BitBlt(dc2,0,0,this.ClientRectangle.Width,this.ClientRectangle.Height,dc1,0,0,13369376);mygraphics.ReleaseHdc(dc1);memoryGraphics.ReleaseHdc(dc2);memoryImage.Save("c:\aaa.jpg");//图片是可以拿到的,并且保存到c:了}privatevoidprintDoc_PrintPage(objectsender,System.Drawing.Printing.PrintPageEventArgse){e.Graphics.DrawImage(memoryImage,0,0);}///<summary>///印刷///</summary>protectedvoidDoPrint(){try{CaptureScreen(this);printPre=newPrintPreviewDialog();printPre.Document=printDoc;printDoc.DefaultPageSettings.Landscape=true;printPre.FormBorderStyle=FormBorderStyle.Fixed3D;printPre.PrintPreviewControl.Zoom=1.0;printPre.AllowTransparency=true;printPre.ShowDialog();//打印机改变之后,最后这一句错误,但是printDoc不是null。}catch(Exceptionex){MessageBox.Show(ex.Message);}}
解决方案
解决方案二:
isitsomesettingwrongwithyourprinter?Canyoutrytoprintatextfileusingnotepad?