将 PrinderDocument 发送到另一个表单
我想将 printDocument 发送到第二个表单,以显示位于第二个表单中的 printPreviewControl 中的内容。
form1代码
中定义了具有公共访问权限的printDocument类
public System.Drawing.Printing.PrintDocument printDocument;
在form1 form2代码
private void Form2_Load(object sender, EventArgs e)
{
Form1 form1 = new Form1;
printPreviewControl.Document = form1.printDocument;
}
我确信form1中的printDocument有要打印的文档,但是当form2加载时,printPreviewControl中没有显示任何内容。在显示 form2 之前应该调用 form1 中 printDocument 的哪个方法?
i want send printDocument to second form to showing that in printPreviewControl which placed in second form.
form1 code
defined printDocument class with public access in form1
public System.Drawing.Printing.PrintDocument printDocument;
form2 code
private void Form2_Load(object sender, EventArgs e)
{
Form1 form1 = new Form1;
printPreviewControl.Document = form1.printDocument;
}
I am sure printDocument in form1 have document to print, but when form2 loaded nothing showed in printPreviewControl. what method of printDocument in form1 should be call before showing form2?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的示例应该可以正常工作,但 PrintPreviewControl 将仅呈现在附加到 PrintDocument 的 PrintPage 事件期间提供的内容。
如果您在 PrintPage 事件期间未执行任何操作,则打印预览将是空白文档。
如果您将 PrintPreviewControl 置于 Form1 上,您可能会收到相同的行为。
Your example should work fine but the PrintPreviewControl will only render what it is fed during the PrintPage event that is attached to the PrintDocument.
If you aren't doing anything during the PrintPage event then the print preview will be a blank document.
Chances are that if you put to PrintPreviewControl on Form1 then you will recieve the same behavior.