Disabling the Print Button in the .net Print Preview Dialog Box

I am working on a C # /. Net application. I want the user to be able to print a preview, but I do not want the user to be able to print from print directly from the preview dialog.

The print preview dialog box has a small printer button that sends the pages you are viewing directly to the printer. The question is, is there a way to get rid of / disable / intercept this button with the click of a button?

+5
source share
5 answers

The PrintPreviewDialog class is actually a wrapper for the PrintPreviewControl class, and this is what gives the toolbar buttons. Any form can contain PrintPreviewControl, so you will need to make the PrintPreviewControl command in the dialog form you created:

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;
    }

}

The Columns property, which is currently set to 1, is the number of pages displayed by the control horizontally across the screen. The Zoom property sets the page scale; 1.0 - full page; therefore, <1.0 will be a thumbnail, a> 1.0 will be an expanded image in the control on the page. What you would like to do with the PreviewDialog class above is to add System.Windows.Forms.ToolStrip to it, and then add buttons to handle scaling and page by the specified properties (columns and scale).

, ( PreviewDialog), :

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

,

+3

, .

:

(ToolStripButton)((ToolStrip)printPreviewDialog1.Controls[1]).Items[0]

, ,

((ToolStripButton)((ToolStrip)printPreviewDialog1.Controls[1]).Items[0]).Enabled = false;
+11

. , . PrintPreviewDialog. JMHO.

class customPrintPreviewDialog : PrintPreviewDialog
{

   public customPrintPreviewDialog() //default constructor
    {
        // over ride the print button default enabled property
       ((ToolStripButton)((ToolStrip)this.Controls[1]).Items[0]).Enabled = false;
    }

   // Add more of your customization here.

}

...

 customPrintPreviewDialog objCPPdialog = new customPrintPreviewDialog();
+3

In VB, I use this, use the code converter in C #:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

    CType(PrintPreviewDialog1.Controls(1), ToolStrip).Items(0).Enabled = False

    PrintPreviewDialog1.ShowDialog()

End Sub
+1
source

this.reportViewer1.ShowPrintButton = False;

-3
source

All Articles