Click here to Skip to main content
16,018,529 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Reposted in question format.I'm new to VB.net and need a simple working example of how to print the contents of a listbox. All of the examples that I've found on the web are either buggy or are overkill. Could someone familiar with VB.net please post code that will show me how to set up the print?
Posted
Updated 5-Mar-14 17:54pm
v2
Comments
joshrduncan2012 5-Mar-14 16:05pm    
Great question for google.
syed shanu 5-Mar-14 20:22pm    
Chk this link http://www.vbforums.com/showthread.php?654856-Printing-Document-from-Listbox

 
Share this answer
 
VB
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        PrintDocument1.Print()
End Sub

Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
        Dim fnt As New Font("Arial", 10, FontStyle.Regular, GraphicsUnit.Point)
        Dim ListBoxItem As String = String.Empty
        For Each LBItem As String In ListBox1.Items
            ListBoxItem = ListBoxItem & vbCrLf & LBItem
        Next
        ListBoxItem = ListBoxItem.Substring(vbCrLf.Length)
        e.Graphics.DrawString(ListBoxItem, fnt, Brushes.Black, 0, 0)
        e.HasMorePages = False
End Sub
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900