Home All Groups Group Topic Archive Search About

Help printing labels...

Author
17 Jul 2006 5:31 PM
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.

Author
17 Jul 2006 5:44 PM
Samuel Shulman
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

Show quoteHide quote
"Kevin" <kev***@cfl.rr.com> wrote in message
news:70inb21kg0a8cp73ckv2e2slfjalvkq7r6@4ax.com...
> 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.
Author
17 Jul 2006 7:49 PM
Kevin
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.




On Mon, 17 Jul 2006 18:44:33 +0100, "Samuel Shulman"
<samuel.shul***@ntlworld.com> wrote:

Show quoteHide quote
>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
>
>"Kevin" <kev***@cfl.rr.com> wrote in message
>news:70inb21kg0a8cp73ckv2e2slfjalvkq7r6@4ax.com...
>> 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.
>