禁用“打印"功能..net打印预览对话框中的按钮 [英] Disabling "print" button in .net print preview dialog

查看:63
本文介绍了禁用“打印"功能..net打印预览对话框中的按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用C#/.net应用程序.我希望用户能够打印预览,但是我不希望用户能够直接从预览对话框的打印中进行打印.

I'm working on a C# / .net app. I want the user to be able to print preview, but I don't want the user to be able to print from the print straight from the preview dialog.

打印预览"对话框上有一个小的打印机按钮,可将预览的页面直接发送到打印机.问题是,有没有办法摆脱/禁用/拦截此按钮的点击?

The print preview dialog has a little printer button on it that sends the previewed pages straight to the printer. Question is, is there a way to get rid of / disable / intercept this button click?

推荐答案

PrintPreviewDialog类实际上是PrintPreviewControl类的包装,它提供了工具栏中的按钮.任何表单都可以承载PrintPreviewControl,因此您要做的就是在创建的对话框表单中承载PrintPreviewControl:

The PrintPreviewDialog class is actually a wrapper around the PrintPreviewControl class and it is what is supplying the buttons in the toolbar. Any form can host the PrintPreviewControl so what you would have to do is host the PrintPreviewControl in a dialog form you create:

public partial class PreviewDialog : Form
{
    public PreviewDialog() {
        this.printPreviewControl1 = new System.Windows.Forms.PrintPreviewControl();
        this.SuspendLayout();
        // 
        // printPreviewControl1
        // 
        this.printPreviewControl1.Dock = System.Windows.Forms.DockStyle.Fill;
        this.printPreviewControl1.Location = new System.Drawing.Point(0, 0);
        this.printPreviewControl1.Name = "printPreviewControl1";
        this.printPreviewControl1.Size = new System.Drawing.Size(292, 273);
        this.printPreviewControl1.TabIndex = 0;
        this.printPreviewControl1.Columns = 1;
        this.printPreviewControl1.Zoom = 1.0;
    }

}

当前设置为1的Columns属性是控件在屏幕上水平显示的页面数.Zoom属性设置页面的比例,1.0为整页;否则为0.所以<1.0将是缩小的图像,而> 1.0将是每页控件中的扩展图像.您想要对上面的PreviewDialog类进行的操作是向其添加System.Windows.Forms.ToolStrip,然后添加按钮来处理缩放以及每个提到的属性(列和缩放)的页面.

The Columns property which is currently being set to 1 is the number of pages displayed by the control horizontally across the screen. The Zoom property sets the scale of the pages, 1.0 being full page; so < 1.0 would be a reduced image and > 1.0 would be an expanded image in the control per page. What you would want to do to the PreviewDialog class above is add a System.Windows.Forms.ToolStrip to it and then add buttons to handle the zoom, and pages per the properties mentioned (Columns and Zoom).

在将显示预览的表单(而不是PreviewDialog表单)中,您将具有以下代码:

In the form that will bring the preview up (not the PreviewDialog form) you would have code like the following:

    private void buttonPrintPreview_Click(object sender, EventArgs e) {
        PreviewDialog dlg = new PreviewDialog();
        dlg.ShowDialog();
        return;
    }

希望这会有所帮助

这篇关于禁用“打印"功能..net打印预览对话框中的按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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