geertd
Gebruiker
- Lid geworden
- 16 nov 2008
- Berichten
- 340
Hallo allemaal,
Ik had een tijdje geleden nog een werkend PrintPreviewDialog in mijn programmaatje.
Nu ik dingen in mijn programma veranderd heb werkt hij niet meer...
Ik heb helemaal niks aan de code voor de preview of de print_document veranderd.
Waarom 'ie het nu dus niet meer doet, GEEN IDEE?!
Ik krijg de volgende Runtime Error:
StackTrace:
De code van de PreviewDialog:
Alvast bedankt,
Geert
Ik had een tijdje geleden nog een werkend PrintPreviewDialog in mijn programmaatje.
Nu ik dingen in mijn programma veranderd heb werkt hij niet meer...
Ik heb helemaal niks aan de code voor de preview of de print_document veranderd.
Waarom 'ie het nu dus niet meer doet, GEEN IDEE?!
Ik krijg de volgende Runtime Error:
Code:
ArgumentException was unhandled
ongeldige parameter
Code:
bij System.Drawing.Imaging.Metafile..ctor(IntPtr referenceHdc, Rectangle frameRect, MetafileFrameUnit frameUnit, EmfType type, String desc)
bij System.Drawing.Imaging.Metafile..ctor(IntPtr referenceHdc, Rectangle frameRect, MetafileFrameUnit frameUnit, EmfType type)
bij System.Drawing.Printing.PreviewPrintController.OnStartPage(PrintDocument document, PrintPageEventArgs e)
bij System.Windows.Forms.PrintControllerWithStatusDialog.OnStartPage(PrintDocument document, PrintPageEventArgs e)
bij System.Drawing.Printing.PrintController.PrintLoop(PrintDocument document)
bij System.Drawing.Printing.PrintController.Print(PrintDocument document)
bij System.Drawing.Printing.PrintDocument.Print()
bij System.Windows.Forms.PrintPreviewControl.ComputePreview()
bij System.Windows.Forms.PrintPreviewControl.CalculatePageInfo()
bij System.Windows.Forms.Control.InvokeMarshaledCallbackHelper(Object obj)
bij System.Threading.ExecutionContext.runTryCode(Object userData)
bij System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)
bij System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
bij System.Windows.Forms.Control.InvokeMarshaledCallback(ThreadMethodEntry tme)
bij System.Windows.Forms.Control.InvokeMarshaledCallbacks()
bij System.Windows.Forms.Control.WndProc(Message& m)
bij System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
bij System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
bij System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
bij System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
bij System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
bij System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
bij System.Windows.Forms.Form.ShowDialog(IWin32Window owner)
bij Veni_Vidi_Didici___Overhoren.Form1.ShowPrintPreviewDialog() in E:\Visual Basic projecten\Veni, Vidi, Disci\Veni Vidi Disci - Overhoren\Form1.vb:regel 1235
bij Veni_Vidi_Didici___Overhoren.Form1.PaginaVoorbeeldWeToolStripMenuItem_Click(Object sender, EventArgs e) in E:\Visual Basic projecten\Veni, Vidi, Disci\Veni Vidi Disci - Overhoren\Form1.vb:regel 1392
bij System.Windows.Forms.ToolStripItem.RaiseEvent(Object key, EventArgs e)
bij System.Windows.Forms.ToolStripMenuItem.OnClick(EventArgs e)
bij System.Windows.Forms.ToolStripItem.HandleClick(EventArgs e)
bij System.Windows.Forms.ToolStripItem.HandleMouseUp(MouseEventArgs e)
bij System.Windows.Forms.ToolStrip.OnMouseUp(MouseEventArgs mea)
bij System.Windows.Forms.ToolStripDropDown.OnMouseUp(MouseEventArgs mea)
bij System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
bij System.Windows.Forms.Control.WndProc(Message& m)
bij System.Windows.Forms.ToolStrip.WndProc(Message& m)
bij System.Windows.Forms.ToolStripDropDown.WndProc(Message& m)
bij System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
bij System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
bij System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
bij System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
bij System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
bij System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
bij Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
bij Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
bij Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
bij Veni_Vidi_Didici___Overhoren.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:regel 81
bij System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
bij System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext activationContext, String[] activationCustomData)
bij Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssemblyDebugInZone()
bij System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
bij System.Threading.ThreadHelper.ThreadStart()
De code van de PreviewDialog:
Code:
Imports System.Drawing
Imports System.Drawing.Drawing2D
'(...)
'(...)
Protected Ratio As Single = 0, CurrRow As Integer = 0
Public Sub ShowPrintPreviewDialog()
If ListView2.Items.Count < 1 Then
MsgBox("De lijst bevat geen werkwoorden", MsgBoxStyle.Information, "Fout")
Exit Sub
End If
Ratio = 1
CurrRow = 0
Dim Prev As New PrintPreviewDialog
With Prev
.Document = PrintDocument1
.Document.DefaultPageSettings.Landscape = True
Ratio = 1
CurrRow = 0
.ShowIcon = False
.ShowDialog()
End With
End Sub
Public Sub ShowPrintSettingsDialog()
If ListView2.Items.Count < 1 Then
MsgBox("De lijst bevat geen werkwoorden", MsgBoxStyle.Information, "Fout")
Exit Sub
End If
With PrintDialog1
.Document = PrintDocument1
.Document.DefaultPageSettings.Landscape = True
Ratio = 1
CurrRow = 0
.ShowHelp = True
.ShowNetwork = True
.AllowSomePages = True
.AllowSelection = False
.AllowCurrentPage = False
.AllowPrintToFile = False
Dim result As DialogResult = .ShowDialog()
If result = Windows.Forms.DialogResult.OK Then
Try
.Document.Print()
Catch
MsgBox("Er is een printerfout opgetreden", MsgBoxStyle.Exclamation, "Fout")
End Try
End If
End With
End Sub
Private Function printgegevensophalen(ByVal onderdeel As String)
If onderdeel = "titel" Then
Dim BestandName = Me.CurrentFilePath.Text
Dim titel
If BestandName = "" Then
titel = "Naamloos"
Return titel
Else
Dim bestandNAAMarr() As String = BestandName.Split("\")
Dim bestandNAAMmetextensie = bestandNAAMarr(bestandNAAMarr.Length - 1)
Dim dotPosition As Integer = bestandNAAMmetextensie.LastIndexOf(".")
Dim bestandNAAM = bestandNAAMmetextensie.Substring(0, dotPosition)
titel = bestandNAAM
Return titel
End If
ElseIf onderdeel = "locatie" Then
Return Me.CurrentFilePath.Text
ElseIf onderdeel = "bestandsoort" Then
Dim bestandsoort = "Werkwoordenlijst: "
Return bestandsoort
End If
End Function
Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
Dim c As ColumnHeader
Dim g As Graphics = e.Graphics
Dim l As Integer = 0
Dim iCount As Integer
Dim f As Font = ListView2.Font
Dim b As Brush = Brushes.Black
Dim currentY As Integer = 0
Dim maxY As Integer = 0
Dim gap As Integer = 1
Dim lvsi As ListViewItem.ListViewSubItem
Dim colLefts(ListView2.Columns.Count) As Integer
Dim colWidths(ListView2.Columns.Count) As Integer
Dim idx As Integer = 0
Dim ii As Integer
Dim lr As RectangleF
e.HasMorePages = False
'Title
'titel ophalen
Dim titel As String = printgegevensophalen("titel")
Dim bestandsoort As String = printgegevensophalen("bestandsoort")
Dim headfont, headfont2, locatiefont, collumnfont As Font
Dim X1 As Integer
Dim Y As Integer
headfont = New Font("Courier New", 16, FontStyle.Bold)
' headfont = New Font(FntFC.Families(0), 22, FontStyle.Bold, GraphicsUnit.Point)
headfont2 = New Font("Courier New", 10, FontStyle.Bold)
collumnfont = New Font(f.SystemFontName, f.Size, FontStyle.Italic)
locatiefont = New Font("Courier New", 8, FontStyle.Italic)
X1 = PrintDocument1.DefaultPageSettings.Margins.Left
e.Graphics.DrawString(bestandsoort & titel & " - " & Date.Today.Day & "-" & Date.Today.Month & "-" & Date.Today.Year, headfont, Brushes.Black, X1 + 30, Y + 40)
With PrintDocument1.DefaultPageSettings
e.Graphics.DrawLine(Pens.Black, 0, Y + 90, e.PageBounds.Width, Y + 90)
End With
'Bestandlocatie
Dim locatie As String = printgegevensophalen("locatie")
If locatie <> "" Then
e.Graphics.DrawString("Locatie: " & locatie, locatiefont, Brushes.DarkGray, X1 + 30, Y + 65)
End If
'Logo
Try
Dim logo As Image = Image.FromFile(installatiepad() & "2007icon.jpg")
e.Graphics.DrawImage(logo, 5, 5, 16, 16)
e.Graphics.DrawString("Veni, Vidi, Didici-overhoringswerkwoordenlijst", locatiefont, Brushes.Black, 26, 6)
Catch
End Try
'Headings
currentY = 100
For Each c In ListView2.Columns
maxY = Math.Max(maxY, g.MeasureString(c.Text, f, c.Width).Height)
colLefts(idx) = l
colWidths(idx) = c.Width
lr = New RectangleF(colLefts(idx), currentY, colWidths(idx), maxY)
' g.DrawString(c.Text, f, b, lr) ' print all columns including hidden columns
MsgBox(5)
If lr.Width > 0 Then g.DrawString(c.Text, collumnfont, b, lr)
l += c.Width
idx += 1
Next
currentY += maxY + gap
g.DrawLine(Pens.Black, 0, currentY, e.PageBounds.Width, currentY)
currentY += gap
'Rows
iCount = ListView2.Items.Count - 1
For ii = CurrRow To iCount
If (currentY + maxY + maxY) > e.PageBounds.Height Then
CurrRow = ii - 1
e.HasMorePages = True
currentY += maxY + gap
Exit For
End If
l = 0
maxY = 0
idx = 0
For Each lvsi In ListView2.Items(ii).SubItems
maxY = Math.Max(maxY, g.MeasureString(lvsi.Text, f, colWidths(idx)).Height)
lr = New RectangleF(colLefts(idx), currentY, colWidths(idx), maxY)
If lr.Width > 0 Then g.DrawString(lvsi.Text, f, b, lr)
idx += 1
Next
currentY += maxY + gap
Next
If (currentY + 60) < e.PageBounds.Height Then
e.HasMorePages = False
Else
CurrRow = ii
e.HasMorePages = True
End If
End Sub
Alvast bedankt,
Geert