Hallo iedereen
Ik gebruik onderstaande om een PDF aan te maken, ik wiet namelijk niet alles zelf opnieuw moeten uittekenen (labels en velden) dus neem ik een screenshot.
Alles werkt goed, maar nu wil ik dat de gebruiker NIET hoeft te zeggen waar het bestand moet op geslaan worden; dat hij dit automatisch zelf doet op bv het bureaublad.
Iemand tips?
Alvast bedankt
Ik gebruik onderstaande om een PDF aan te maken, ik wiet namelijk niet alles zelf opnieuw moeten uittekenen (labels en velden) dus neem ik een screenshot.
Alles werkt goed, maar nu wil ik dat de gebruiker NIET hoeft te zeggen waar het bestand moet op geslaan worden; dat hij dit automatisch zelf doet op bv het bureaublad.
Iemand tips?
Alvast bedankt
Code:
'START PRINTEN VOLLEDIGEWANDENBEHEER
'--------------------------------------
Dim img As Bitmap
Dim WithEvents pd As PrintDocument
'MAAK EEN SCREENSHOT
Function CaptureForm1() As Bitmap
'VERBERG AFBEELDINGEN DIE NIET NODIG ZIJN
LineShape1.Visible = False
lblclaimnr.Visible = False
txtclaimnr.Visible = False
lbldossiernr.Visible = False
txtdossiernr.Visible = False
lblklant.Visible = False
txtklant.Visible = False
lblclaimsapnr.Visible = False
txtclaimsapnr.Visible = False
btnsave.Visible = False
btnprint.Visible = False
'SET AFBEELDING
Dim g1 As Graphics = Me.CreateGraphics()
Dim MyImage As New Bitmap(Me.ClientRectangle.Width, (Me.ClientRectangle.Height), g1)
Dim g2 As Graphics = Graphics.FromImage(MyImage)
Dim dc1 As IntPtr = g1.GetHdc()
Dim dc2 As IntPtr = g2.GetHdc()
BitBlt(dc2, 0, 0, Me.ClientRectangle.Width, (Me.ClientRectangle.Height), dc1, 0, 0, 13369376)
g1.ReleaseHdc(dc1)
g2.ReleaseHdc(dc2)
'AFBEELDING OPSLAAN IN PRINTMAP INDIEN NODIG
'MyImage.Save("K:\Dossiers-Volledigewanden\A.Claims\claim.bmp")
Return MyImage
End Function
'GEEN FLAUW IDEE VAN WAT DIT DOET
<DllImport("gdi32.DLL", EntryPoint:="BitBlt", _
SetLastError:=True, CharSet:=CharSet.Unicode, _
ExactSpelling:=True, _
CallingConvention:=CallingConvention.StdCall)> _
Private Shared Function BitBlt(ByVal hdcDest As IntPtr, ByVal nXDest As Integer, ByVal nYDest As Integer, ByVal nWidth As Integer, ByVal nHeight As Integer, ByVal hdcSrc As IntPtr, ByVal nXSrc As Integer, ByVal nYSrc As Integer, ByVal dwRop As System.Int32) As Boolean
' Leave function empty - DLLImport attribute forwards calls to MoveFile to
' MoveFileW in KERNEL32.DLL.
End Function
Private Sub btnprint_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnprint.Click
Dim dossiernr As String
dossiernr = txtdossiernr.Text
lblprintdate.Visible = True
dtpclaimdatum.Visible = False
MsgBox("Claim op dossier: " & dossiernr & " wordt afgedrukt.", MsgBoxStyle.Information, "MELDING")
img = CaptureForm1()
pd = New PrintDocument
Dim claimdoc As New Volledigewandenbeheer_Claims_document
If PrintDialog1.ShowDialog = DialogResult.OK Then
pd.PrinterSettings.PrinterName = PrintDialog1.PrinterSettings.PrinterName
claimdoc.SendToBack()
Dim ps As PaperSize
ps = pd.PrinterSettings.PaperSizes(0)
pd.DefaultPageSettings.PaperSize = ps
pd.DefaultPageSettings.Landscape = False
pd.DefaultPageSettings.Margins.Top = 50
pd.DefaultPageSettings.Margins.Left = 0
pd.Print()
LineShape1.Visible = True
lblclaimnr.Visible = True
txtclaimnr.Visible = True
lbldossiernr.Visible = True
txtdossiernr.Visible = True
lblklant.Visible = True
txtklant.Visible = True
lblclaimsapnr.Visible = True
txtclaimsapnr.Visible = True
btnsave.Visible = True
btnprint.Visible = True
Else
End If
lblprintdate.Visible = False
dtpclaimdatum.Visible = True
claimdoc.BringToFront()
claimdoc.Focus()
End Sub
'this method will be called each time when pd.printpage event occurs
Sub pd_PrintPage(ByVal sender As Object, ByVal e As PrintPageEventArgs) Handles pd.PrintPage
Dim x As Integer = e.MarginBounds.X
Dim y As Integer = e.MarginBounds.Y
e.Graphics.DrawImage(img, x, y)
e.HasMorePages = False
End Sub
'STOP PRINTEN VOLLEDIGEWANDENBEHEER
'--------------------------------------