在printpreviewdialog中添加保存按钮 [英] add save button in printpreviewdialog

查看:124
本文介绍了在printpreviewdialog中添加保存按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨 我的Windows应用程序中有PrintPreviewDialog1.该打印预览对话框将从主表单中填充.因此,PrintPreviewDialog的默认控件具有print,zoom等.
我的问题:如何编辑此控件以添加保存按钮?我正打算将预览的文档另存为PDF.

Hi I have PrintPreviewDialog1 in my windows application. This print preview dialog will be populated from the main form. So the default control of the PrintPreviewDialog has print ,zoom etc.
My question: How do I edit this control programaticaly to add save button ? I am tring to save the previewed document as PDF.

推荐答案

您好,可以像这样创建自定义预览控件..

类文档应引用using System.Windows.Forms;

Hi create a custom preview control like this..

the class document should have a reference to using System.Windows.Forms;

class CustomPrintPreviewDialog : System.Windows.Forms.PrintPreviewDialog
{
    public CustomPrintPreviewDialog()
        : base()

    {
        if(this.Controls.ContainsKey("toolstrip1"))
        {

            ToolStrip tStrip1 = (ToolStrip)this.Controls["toolstrip1"];
            ToolStripButton button1 = new ToolStripButton();
            button1.Text = "Save";
            button1.Click += new EventHandler(SaveDocument);
            button1.Visible = true;
            tStrip1.Items.Add(button1);
        }
    }

    protected void SaveDocument(object sender, EventArgs e)
    {
        // code for save the document
        MessageBox.Show("OK");
    }
}



在保存文档功能中实现您的保存逻辑.

然后,您可以将该控件实例化为



Implement your save logic in the save document function.

Then you can instantiate this control as

<br />
<br />
            CustomPrintPreviewDialog dialog1 = new CustomPrintPreviewDialog();<br />
            dialog1.Show();<br />



并将whaterver属性或调用方法设置为普通打印预览对话框.


但基本上保存为PDF只是使用pdf打印机.该控件已经有一个打印按钮.如您所问,我给了这种方式.由您决定如何实现保存功能.



and set whaterver properties or call methods as normal print preview dialog.


But basically save to PDF is just use the pdf printer. This control already have a print button. As you asked I gave given this way. Upto you how you want to implement the save function.


这篇关于在printpreviewdialog中添加保存按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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