我有一个 Windows 窗体,其中包含图像和该图像上的一些文本框。在将这些文本框与该图像一起填充后,我需要打印内容。我使用了下面的代码,但它只打印图像,而不是文本框中的值。
PrintDocument printDocument = new PrintDocument();
printDocument.PrintPage += PrintDocumentOnPrintPage;
printDocument.PrinterSettings.DefaultPageSettings.PaperSize = new System.Drawing.Printing.PaperSize("a2", this.Width, this.Height);
PrintDialog pdg = new PrintDialog();
pdg.Document = printDocument;
// if (pdg.ShowDialog() == DialogResult.OK)
//{
printDocument.Print();
//}
private void PrintDocumentOnPrintPage(object sender, PrintPageEventArgs e)
{
Graphics myGraphics = panel1.CreateGraphics();
Size s = this.Size;
Bitmap memoryImage = new Bitmap(panel1.Width , panel1.Height, myGraphics);
Graphics memoryGraphics = Graphics.FromImage(memoryImage);
Point screenLoc =PointToScreen(panel1.Location); // Get the location of the Panel in Screen Coordinates
memoryGraphics.CopyFromScreen(screenLoc.X, screenLoc.Y, 0, 0, s);
e.Graphics.DrawImage(memoryImage, 0, 0);
}
但我仍然无法管理打印尺寸