Mark,
For PrintPreview, you have to implement your own preview. We implemented
PrintPreview using PrintPreviewDialog using given quoted code. Let me know
if this help or contact me at my msn messenger id : (e-mail address removed)
Thanks
Shahzad Godil
Karachi-Pakistan
Imports System
Public Class PrintPreview
Inherits System.Windows.Forms.Form
Friend WithEvents PrintDocument1 As System.Drawing.Printing.PrintDocument
Friend WithEvents PrintPreviewDialog1 As
System.Windows.Forms.PrintPreviewDialog
Public VisioDrawingPage As Microsoft.Office.Interop.Visio.Page
Public Sub New()
InitializeComponent()
End Sub
Private Sub InitializeComponent()
Dim resources As System.Resources.ResourceManager = New
System.Resources.ResourceManager(GetType(PrintPreview))
Me.PrintPreviewDialog1 = New System.Windows.Forms.PrintPreviewDialog
Me.PrintDocument1 = New System.Drawing.Printing.PrintDocument
'
'PrintPreviewDialog1
'
Me.PrintPreviewDialog1.AutoScrollMargin = New System.Drawing.Size(0, 0)
Me.PrintPreviewDialog1.AutoScrollMinSize = New System.Drawing.Size(0, 0)
Me.PrintPreviewDialog1.ClientSize = New System.Drawing.Size(400, 300)
Me.PrintPreviewDialog1.Enabled = True
Me.PrintPreviewDialog1.Icon =
CType(resources.GetObject("PrintPreviewDialog1.Icon"), System.Drawing.Icon)
Me.PrintPreviewDialog1.Location = New System.Drawing.Point(21, 54)
Me.PrintPreviewDialog1.MinimumSize = New System.Drawing.Size(375, 250)
Me.PrintPreviewDialog1.Name = "PrintPreviewDialog1"
Me.PrintPreviewDialog1.TransparencyKey = System.Drawing.Color.Empty
Me.PrintPreviewDialog1.Visible = False
'
'PrintDocument1
'
'PrintPreview
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(672, 462)
Me.Name = "PrintPreview"
Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
Me.WindowState = System.Windows.Forms.FormWindowState.Minimized
End Sub
Private Sub PrintDocument1_PrintPage(ByVal sender As Object, ByVal e As
System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
GetMetaFile(e)
End Sub
Public Sub PreviewDrawing(ByVal DrawingPage As
Microsoft.Office.Interop.Visio.Page)
Try
VisioDrawingPage = DrawingPage
'PrintDocument1.DefaultPageSettings.Landscape = ' get from proj page
settings
PrintPreviewDialog1.Document = PrintDocument1
PrintPreviewDialog1.WindowState = FormWindowState.Maximized
PrintPreviewDialog1.ShowDialog()
Catch ex As Exception
MessageBox.Show(ex.Message.ToString() & ex.StackTrace.ToString())
End Try
End Sub
Private Sub showMetafile(ByVal metafile As System.drawing.imaging.Metafile,
_
ByRef e As System.Drawing.Printing.PrintPageEventArgs)
e.Graphics.DrawImage(metafile, e.PageBounds)
End Sub
Private Sub GetMetaFile(ByRef e As
System.Drawing.Printing.PrintPageEventArgs)
Dim pageMetafile As System.Drawing.Imaging.Metafile = Nothing
Dim pagePicture As stdole.IPictureDisp
Dim convertedPictureHandle As IntPtr = Nothing
Dim temporaryShape As Microsoft.Office.Interop.Visio.Shape
Dim pageWidth As Double
Dim pageHeight As Double
pageWidth = VisioDrawingPage.PageSheet.CellsSRC( _
CShort(Microsoft.Office.Interop.Visio.VisSectionIndices. _
visSectionObject), _
CShort(Microsoft.Office.Interop.Visio.VisRowIndices. _
visRowPage), _
CShort(Microsoft.Office.Interop.Visio.VisCellIndices. _
visPageWidth)).ResultIU
pageHeight = VisioDrawingPage.PageSheet.CellsSRC( _
CShort(Microsoft.Office.Interop.Visio.VisSectionIndices. _
visSectionObject), _
CShort(Microsoft.Office.Interop.Visio.VisRowIndices. _
visRowPage), _
CShort(Microsoft.Office.Interop.Visio.VisCellIndices. _
visPageHeight)).ResultIU
temporaryShape = VisioDrawingPage.DrawRectangle(0, 0, pageWidth, pageHeight)
temporaryShape.CellsSRC( _
CShort(Microsoft.Office.Interop.Visio.VisSectionIndices. _
visSectionObject), _
CShort(Microsoft.Office.Interop.Visio.VisRowIndices. _
visRowFill), _
CShort(Microsoft.Office.Interop.Visio.VisCellIndices. _
visFillPattern)).ResultIU = 0
pagePicture = VisioDrawingPage.Picture
convertedPictureHandle = New IntPtr(pagePicture.Handle)
pageMetafile = New System.Drawing.Imaging.Metafile(convertedPictureHandle,
False)
temporaryShape.Delete()
If (Not pageMetafile Is Nothing) Then
showMetafile(pageMetafile, e)
End If
End Sub
End Class