Help printing labels...

  • Thread starter Thread starter Kevin
  • Start date Start date
K

Kevin

In my VB2005 Windows Forms program I want to be able to click a button
and have my Dot Matrix printer print one 15/16 x 3 1/2 address label
from continuous forms.

I'm trying to use a PrintDocument, but don't know how to set up the
page size to be only one label.
 
Not sure but the following may help you

'Set the page settings
Dim obPage As New PageSettings
obpage.PaperSize.Kind = 'PaperKind Enumeration value
'Assign theis object to the PrintDocument.Document member

You may set it to custom size (it is a value in the enum) and then set it to
the required size
hth,
Samuel
 
Thanks for the reply Samuel, but after more searching, I finally found
someone else's code I used as an example.


Private Sub mnuMailLabel_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles mnuMailLabel.Click
Dim doc As PrintDocument = New PrintDocument
Dim printer As PrintDialog = New PrintDialog

printer.Document = doc
printer.PrinterSettings.PrinterName = My.Settings.MPrinter
printer.Document.DefaultPageSettings.PaperSize = New
Printing.PaperSize(Printing.PaperKind.Custom, 350, 100)

AddHandler doc.PrintPage, AddressOf PrintPageHandler
doc.Print()
End Sub

Private Sub PrintPageHandler(ByVal sender As Object, ByVal e As
PrintPageEventArgs)
Dim canvas As Graphics = e.Graphics
Dim _font As Font = New Font("Tahoma", 10)
Dim _brush = Brushes.Black
Dim PrintString As String

PrintString = txtFName.Text & " "
If Trim(txtMI.Text) <> "" Then
PrintString = PrintString & VB.Left(txtMI.Text, 1) & " "
End If
PrintString = PrintString & txtLName.Text & vbCrLf &
txtAddress.Text & vbCrLf & txtCity.Text & ", " & txtState.Text & " " &
txtZip.Text

canvas.DrawString(PrintString, _font, _brush, 0, 0)
End Sub


The line:
printer.Document.DefaultPageSettings.PaperSize = New
Printing.PaperSize(Printing.PaperKind.Custom, 350, 100)

was what I couldn't quite figure out how to do. This code works fine
in my program.
 
Back
Top