GDI+ Error in Print Preview - Plz Help

A

Asif

Hi all,

I am using the following sample code (Visio 2003 SDK) for print-preview
the visio drawing.

The issue is there once the following procedure is called it is giving
the following error:

A Generic error occured in GDI+
********************* Exception Text ******************************
System.Runtime.InteropServices.ExternalException: A generic error
occured in GDI
at System.Windows.Forms.PrintPreviewControl.CalculatePageInfo()
at System.Windows.Forms.Control.InvokeMarshaledCallBacks()

Can anyone tell me about how to solve the issue.

Thanks

Asif

**************************** Code for using Print Preview
Private Sub PrintDocument1_PrintPage(ByVal sender As Object, ByVal e As
System.Drawing.Printing.PrintPageEventArgs) Handles
PrintDocument1.PrintPage
GetMetaFile(e)
End Sub

Public Sub PrintPreview(ByVal DrawingPage As
Microsoft.Office.Interop.Visio.Page)
Try
VisioDrawingPage = DrawingPage
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)
' Draw drawing Image for print preview.
e.Graphics.DrawImage(metafile, e.PageBounds)
End Sub

Private Sub GetMetaFile(ByRef e As
System.Drawing.Printing.PrintPageEventArgs)
' This procedure is used to prepare file used for print
preview.
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top