こんにちは、MSDN からこのコードを取得しました。問題がわかりません、お役に立てれば幸いです。エラーは、printForm1 という単語が含まれる 2 行にあります。私のフォームは実際には 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;
}