Printing the Content of a Listbox (VB.Net 2003)

XandrilZaax

New member
Joined
Jun 3, 2006
Messages
3
Programming Experience
Beginner
Hey all. I'm trying to implement a procedure that prints just the contents of a listbox, and cant figure it out. Does anyone know how to do this?
 
Printing from a TextBox.

Hello.
Start a project and put a button on it.
What you do next is get a PrintPreviewDialog and a PrintDocument
from the Toolbox. Click on the PrintPreviewDialog in the lower pane
and in its Properties window set its Document to the PrintDocument.
Click the button and put this in its event:
VB.NET:
PrintPreviewDialog1.ShowDialog()
Then in the Code Editor select from the left drop down menu -
PrintDocument. And from the right drop down select - PrintPage.
Put the code in so it looks like this:
VB.NET:
 Private Sub PrintDocument1_PrintPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
        Dim f As New Font("Eurostyle", 16, FontStyle.Regular)
        Dim x As Single, y As Single
        Dim h As Single = 30
        x = e.MarginBounds.Left
        y = e.MarginBounds.Top
        Dim item As String
        For Each item In ListBox1.Items
            e.Graphics.DrawString(item, f, Brushes.Black, x, y)
            y += h
        Next
    End Sub
Good Luck.
 
Back
Top