如何从打印预览中显示打印设置? [英] How to present print settings from print preview?

查看:58
本文介绍了如何从打印预览中显示打印设置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的 C# 项目中,我有 2 个打印函数.一个直接打印文档,另一个向用户提供预览并在用户选择时打印.

In my C# Project I have 2 print functions. One that prints the document directly and another that presents a preview to the user and prints if the user chooses to do so.

虽然两种方法都有效,但直接打印版本会在打印文档之前显示打印设置窗口.

While both methods are working, the direkt print version presents the print settings window before it prints the document.

private void printButton_Click(object sender, EventArgs e)    
{
    PrintDialog printDialog = new PrintDialog();
    printDialog.Document = printIssues;
    printDialog.UseEXDialog = true;

    if (DialogResult.OK == printDialog.ShowDialog())
    {
        printIssues.DocumentName = "Some Name";
        printIssues.DefaultPageSettings.Landscape = true;
        printIssues.Print();
    }
}

private void previewButton_Click(object sender, EventArgs e)
{
    PrintPreviewDialog printPreview = new PrintPreviewDialog();
    printPreview.Icon = Properties.Resources.favicon;
    printPreview.Document = printIssues;
    printIssues.DefaultPageSettings.Landscape = true;
    ((Form)printPreview).WindowState = FormWindowState.Maximized;

    printPreview.ShowDialog();
}

我首先展示预览的第二个版本,一旦我单击打印按钮,文档就会在默认打印机上打印,而不会出现设置"窗口.我尝试了一些东西并安静地搜索了一段时间,但找不到任何对我有帮助的东西.

The second Version where I present the preview first, once I click the print button the document gets printed on the Default Printer without presenting the Settings window. I've tried some things and searched quiet some time but couldn't find anything that helped me.

感谢您的帮助.

推荐答案

恐怕这是 PrintPreviewDialog 的一个已知限制.它需要知道用于绘制布局的打印机,因此它使用默认打印机.

I'm afraid this is a known limitation of the PrintPreviewDialog. It needs to know the printer to draw the layout so it uses the default printer.

我过去也遇到过同样的问题,我相信可以通过在显示 PrintPreviewDialog 之前显示 PrintDialog 来解决.

I've had the same problem in the past, and I believe it can be solved by showing a PrintDialog before showing the PrintPreviewDialog.

private void previewButton_Click(object sender, EventArgs e)
{
    PrintDialog printDialog = new PrintDialog();
    if (DialogResult.OK == printDialog.ShowDialog())
        {
             PrintPreviewDialog printPreview = new PrintPreviewDialog();
             printPreview.Document = printIssues;

             // this is were you take the printersettings from the printDialog
             printPreview.Document.PrinterSettings = printDialog.PrinterSettings;

             printIssues.DefaultPageSettings.Landscape = true;
             printPreview.ShowDialog();         
        }  
}

另一种解决方法是制作您自己的 PrintPreviewDialog.但它需要更多的编码.

Another workaround would be to make your own PrintPreviewDialog. But it requires more coding.

你能告诉我上面的代码是否适合你吗?

can you tell me if the above code works for you?

这篇关于如何从打印预览中显示打印设置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆