如何在C#中使用FileDialog和PrintDialog? [英] How to use FileDialog and PrintDialog in C#?

查看:73
本文介绍了如何在C#中使用FileDialog和PrintDialog?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

现在,我正在尝试创建一个用于打印文档(* .txt或* .doc)的小型应用程序.

我尝试将应用程序与textbox和richtextbox一起使用,它可以成功打印,
但是,如果文本长度超过一页.仅显示一页.它忽略其余的内容.

所以我想将文本保存在另一个文件中.
我也想从文件对话框中选择一个文件,并且允许所选文件打印多页.打印预览也在当前应用程序中.

所以有人可以帮我构建应用程序吗?

预先感谢.

Now I am trying to create a small application for printing a document(*.txt or *.doc).

I tried using the application with textbox and richtextbox, it prints successfully,
But if the Text length is more than one page. It shows only one page. It Ignores the remaining.

So I would like to save the text in another file.
I also like to select a file from file dialog and the selected file is allowed to print with multiple pages. print preview is also in the current application.

So Could anyone help me out Building the application.

Thanks in advance.

推荐答案



这是一个例子.
希望对您有所帮助.
Hi,

Here is a example.
Hope it helps.
private void InvokePrint(object sender, RoutedEventArgs e)
    {
        // Create the print dialog object and set options
        PrintDialog pDialog = new PrintDialog();
        pDialog.PageRangeSelection = PageRangeSelection.AllPages;
        pDialog.UserPageRangeEnabled = true;

        // Display the dialog. This returns true if the user presses the Print button.
        Nullable<Boolean> print = pDialog.ShowDialog();
        if (print == true)
        {
            XpsDocument xpsDocument = new XpsDocument("C:\\FixedDocumentSequence.xps", FileAccess.ReadWrite);
            FixedDocumentSequence fixedDocSeq = xpsDocument.GetFixedDocumentSequence();
            pDialog.PrintDocument(fixedDocSeq.DocumentPaginator, "Test print job");
        }
    }


这篇关于如何在C#中使用FileDialog和PrintDialog?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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