Possible modification of PrintPreviewDialog?

I am currently doing the following:

  • Using the Built-in .NET PrintPreviewDialog
  • Attaching my own Click handler to the Print button, which allows the user to select a printer before final printing.

All this works, HOWEVER, the OnprintToolStripButtonClick event still sends the document to the default printer before the user can select the actual printer and click "Print" (which works, but they get an additional copy on the printer by default primarily from the old handler) .

Can I remove this built-in Click handler? I tried using the other methods mentioned here regarding the use of EventHandlerList to remove handlers, but it does not work for the inline print event. Here is a copy of my current code, if that helps clarify:

// ... Irrelevant code before this
private PrintPreviewDialog ppdlg;

ToolStrip ts = new ToolStrip();
ts.Name = "wrongToolStrip";
foreach (Control ctl in ppdlg.Controls)
{
   if (ctl.Name.Equals("toolStrip1"))
   {
      ts = ctl as ToolStrip;
      break;
   }
}
ToolStripButton printButton = new ToolStripButton();
foreach (ToolStripItem tsi in ts.Items)
{
   if (tsi.Name.Equals("printToolStripButton"))
   {
      printButton = tsi as ToolStripButton;
   }
}
printButton.Click += new EventHandler(this.SelectPrinterAfterPreview);
// ... Irrelevant code afterwards omitted


// Here is the Handler for choosing a Printer that gets called after the
// PrintPreviewDialog "Print" button is clicked.
private void SelectPrinterAfterPreview(object sender, EventArgs e)
{
   frmMainPage frmMain = (frmMainPage)this.MdiParent;
   if (frmMain.printDialog1.ShowDialog() == DialogResult.OK)
   {
      pd.PrinterSettings.PrinterName = frmMain.printDialog1.PrinterSettings.PrinterName;
      pd.PrinterSettings.Copies = frmMain.printDialog1.PrinterSettings.Copies;
      pd.Print();
   }
}
+5
source share
2 answers

Since you have access to the buttons on the toolbar, delete the old print button and add your own. Assign the image using the default print button, and everything is set. The woudl code looks something like this:

ts.Items.Remove(printButton);
ToolStripButton b = new ToolStripButton();
b.ImageIndex = printButton.ImageIndex;
b.Visible = true;
ts.Items.Insert(0, b);
b.Click += new EventHandler(this.SelectPrinterAfterPreview);
+6
source

I think that replacing buttons or using Control Names from PrintPreviewDialog is not a good option.

Net1 Net2 ToolBar. .

PrintPreviewDialog - PrintPreviewControl.

.

PrintPreview Code-Project (CoolPrintPreviewDialog) Enhanced PrintPreviewDialog.

PrvDialog, "", PageSelDialog, Range to Print ( , , " ", "" ).

OnBeginPrint/suscribe BeginPrint PrintDocument. SelDialog, DefaultPageSettings PrintRange, FromPage, ToPage.

, PrintToPrinter, Preview Print From PrintButon. PrintController.IsPreview, .

+1

All Articles