从PrintPreviewDialog

时间:2018-06-07 21:09:17

标签: c# winforms print-preview

我想将标题设置为我在Windows窗体中的PrintPreviewDialog中使用的文档。我尝试了一些东西,但是肯定这不是将TITLE设置为这种类型的文档的方法。你能帮帮我吗?

private void pd_print(object sender, PrintPageEventArgs e)
{    
  Graphics gr = e.Graphics;
  gr.DrawString("Sales", new Font(FontFamily.GenericMonospace, 12, FontStyle.Bold), new SolidBrush(Color.Black), new Point(40, 40));
}

private void tiparireToolStripMenuItem_Click(object sender, EventArgs e)
{        
  PrintDocument pd = new PrintDocument();
  pd.PrintPage += new PrintPageEventHandler(this.pd_print);

  PrintPreviewDialog dlg = new PrintPreviewDialog();
  dlg.Document = pd;
  dlg.ShowDialog();
}

1 个答案:

答案 0 :(得分:0)

预览对话框只是一个隐藏Text属性的表单。

PrintPreviewDialog dlg = new PrintPreviewDialog();
((Form)dlg).Text = "My Title";
dlg.Document = pd;
dlg.ShowDialog();