Во-первых, вы должны установить принтер по умолчанию для вашей системы на «Имя принтера Nitro» * Код 1001 *
, приведенный ниже, может помочь вам сделать это
Private Sub set_Nitro_As_Default()
Dim prn As Printer
If Printers.Count > 0 Then
For Each prn In Printers
If prn.DeviceName = [Nitro Printer Name] Then 'printer that u want to use
Set Printer = prn
Exit For
End If
Next prn
End If
End Sub
для печати некоторого текста, этикетки или графических объектов, которые вы необходимо добавить в ваш файл picturebox. Он содержит все объекты, которые вы хотите распечатать.
после того, как вы подготовите все объекты, такие как метка или форма, и все, что готово к печати, вызовите этот саб, чтобы сохранить ваше изображение в окне. bmp file
'add this declaration on top of your project
Private Declare Function SendMessage Lib "user32.dll" Alias "SendMessageA" _
(ByVal hwnd As Long, ByVal wMsg As Long, _
ByVal wParam As Long, ByVal lParam As Long) As Long
Private Const WM_PAINT = &HF
Private Const WM_PRINT = &H317
Private Const PRF_CLIENT = &H4& ' Draw the window's client area
Private Const PRF_CHILDREN = &H10& ' Draw all visible child
Private Const PRF_OWNED = &H20& ' Draw all owned windows
'this function save PicBox image in FileName path
'PicBox Contain All thing which you want to print
Public Sub SavePictureBox(PicBox As PictureBox, FileName As String)
Dim rv As Long
Dim ar As Boolean
With PicBox
'Save ReDraw value
ar = .AutoRedraw
.AutoRedraw = True
'Draw controls to picture box
rv = SendMessage(.hwnd, WM_PAINT, .hdc, 0)
rv = SendMessage(.hwnd, WM_PRINT, .hdc, _
PRF_CHILDREN Or PRF_CLIENT Or PRF_OWNED)
'save picture box
SavePicture .Image, FileName
.Cls
'Restore ReDraw
.AutoRedraw = ar
End With
End Sub
Вы должны добавить что-то подобное в свою основную команду печати
private sub iPrint()
'firstly set your intended printer as default
call set_Nitro_As_Default
'set some Generic setting
Printer.PrintQuality = vbPRPQHigh
Printer.PaperSize = vbPRPSA4
for i=1 to [your intended page count]
'do some thing for Arrange your labels and objects to make it ready to print
'after prepare your all thing on picturebox
call SavePictureBox([printed PictureBox], App.path & "\tmp.bmp")
'print this page
'note that you can set margin and your printed page size
Printer.PaintPicture LoadPicture(App.Path & "\tmp.bmp"), 0, 0, _
LoadPicture(App.Path & "\tmp.bmp").Width, _
LoadPicture(App.Path & "\tmp.bmp").Height, _
0, 0, _
Printer.Width, _
Printer.Height
Printer.NewPage
next i
Printer.EndDoc
end sub
все готово