I have a PrintPreviewDialog control onto which I've added an extra button in the toolbar, to export the contents of the print preview window as an Excel spreadsheet. As the control is intended to be a "black box" to any calling code, I don't have access to the bits and pieces that the calling code uses to make up the PrintDocument; I just have the PrintDocument itself. Is this doable?
Here is the code to add the additional button onto the toolbar in my PrintPreviewDialog:
Imports System.Windows.Forms
Imports Microsoft.Office.Interop
Imports System.Drawing
Public Class myPrintPreview
Private bitmap As Bitmap
Sub New()
InitializeComponent()
Try
'Get the toolstrip from the base control
Dim ts As ToolStrip = CType(Me.PrintPreviewDialog1.Controls(1), ToolStrip)
'Add a new button
Dim myExportButton As ToolStripItem
myExportButton = ts.Items.Add("Export", System.Drawing.Image.FromFile("C:\omnibus\testimage.png"), New EventHandler(AddressOf myExportButtonClicked))
myExportButton.DisplayStyle = ToolStripItemDisplayStyle.Image
'Relocate the item to be the second button on the toolstrip
ts.Items.Insert(1, myExportButton)
Catch ex As Exception
MsgBox("Error code " & ex.Message)
End Try
End Sub
End Class
"myExportButtonClicked" is another procedure which is supposed to take the content of the document shown in the print preview dialog and save it as an Excel.Workbook or Excel.Worksheet.
The question is, how do I access that content, when this control is designed to be made available to a number of applications which pass a PrintDocument to the control?