Re: VB Printer Dialog Problem (VB6)
- From: andy.vandierendonck@xxxxxxxxxx
- Date: 1 Jul 2006 08:11:41 -0700
It's a lot to post if I want to show
my print routine. I use own sub routine's and functions
that I've placed in a public bas module. My language
is dutch, so I think it won't be easy to read
my code, unless I transulate it to english wich
would also be a lot of work to do that.
But I just was wondering if it was possible to run
print commands without the printer receive it, such
as block the printer. I already have a solution to know
the total number of pages and print it on every page,
wich I said in my previous post. First let the my print
routine run on an userform, because almost every properties
in the printer object are also available in the userform properties.
Here's an example when clicking on a printbutton.
The form 'frmPrintForm' is only be used for 'testprinting'
Option Explicit
Dim PRNT As Object, TotalPages As Integer
Private Declare Function GetDeviceCaps Lib "gdi32" _
(ByVal hdc As Long, ByVal nindex As Long) As Long
Private Const PHYSICALOFFSETX As Long = 112
Private Const PHYSICALOFFSETY As Long = 113
Private Declare Function SetBkMode Lib "gdi32" _
(ByVal hdc As Long, ByVal nBkMode As Long) As Long
Private Const TRANSPARENT = 1
Private Const OPAQUE = 2
Private Sub SetMargin(ByVal Left_M As Single, ByVal Top_M As Single)
With PRNT
.ScaleLeft = .ScaleX(GetDeviceCaps(.hdc, PHYSICALOFFSETX), _
vbPixels, .ScaleMode) - Left_M
.ScaleTop = .ScaleY(GetDeviceCaps(.hdc, PHYSICALOFFSETY), _
vbPixels, .ScaleMode) - Top_M
.CurrentX = 0
.CurrentY = 0
End With
End Sub
Private Sub New_Page()
If PRNT Is frmPrintForm Then
TotalPages = TotalPages + 1
Else
PRNT.NewPage
End If
End Sub
Private Sub Print_Routine()
PRNT.Print
PRNT.ScaleMode = vbMillimeters
PRNT.FontTransparent = True
SetBkMode PRNT.hdc, TRANSPARENT
Call SetMargin (12, 15)
' Example when there's a new page:
Call New_Page
Call SetMargin (12, 15)
' Next print commands ...
End Sub
Private Sub cmdPrint_Click()
On Error GoTo 0
Call VBPrinterDialog(Me)
Set PRNT = frmPrintForm
TotalPages = 1
Load frmPrintForm
Call Print_Routine
frmPrintForm.Cls: Unload frmPrintForm
'at this point the TotalPages are known
'now run the same print routine again and print
Set PRNT = Printer
Call Print_Routine
PRNT.EndDoc
End Sub
Thanks for all the help, I've learned some useful
stuff here!
Andy
.
- Follow-Ups:
- Re: VB Printer Dialog Problem (VB6)
- From: Mike Williams
- Re: VB Printer Dialog Problem (VB6)
- Prev by Date: Re: object data type
- Next by Date: Re: VB Printer Dialog Problem (VB6)
- Previous by thread: Re: object data type
- Next by thread: Re: VB Printer Dialog Problem (VB6)
- Index(es):