在 C# 中,我在表单上有一个面板,我想打印其中的内容。面板的内容是DrawLines
方法中的行。
目前我无法在打印预览中查看或打印面板上的线条。面板的边框确实出现了。
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
panel1.CreateGraphics().DrawLines(new Pen(Color.Black),
new Point[]{new Point(10,10),new Point(50,50)});
}
private void PrintPanel(Panel pnl)
{
PrintDialog myPrintDialog = new PrintDialog();
PrinterSettings values;
values = myPrintDialog.PrinterSettings;
myPrintDialog.Document = printDocument1;
printDocument1.PrintController = new StandardPrintController();
printDocument1.PrintPage +=
new System.Drawing.Printing.PrintPageEventHandler(printDocument1_PrintPage);
printPreviewDialog1.Document = printDocument1;
printPreviewDialog1.ShowDialog();
//printDocument1.Print();
printDocument1.Dispose();
}
void printDocument1_PrintPage(object sender, PrintPageEventArgs e)
{
Bitmap bmp = new Bitmap(panel1.Width, panel1.Height);
panel1.DrawToBitmap(bmp, new Rectangle(0, 0, panel1.Width, panel1.Height));
e.Graphics.DrawImage(bmp, panel1.Width, panel1.Height);
}
为什么面板中的线条没有在打印预览或打印中显示?