Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How do I print contents of a listbox?

Posted on 2011-03-21
2
Medium Priority
?
1,239 Views
Last Modified: 2012-05-11
How do I print contents of a listbox?
This is what I have, but get error messages:

 Dim streamToPrint As StreamReader

        Try
            streamToPrint = New StreamReader(Me.ListBoxAlpha.Items.ToString)
            Dim pd As New PrintDocument()
0
Comment
Question by:gs99
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 500 total points
ID: 35184614
You would do something along these lines:
Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim pdlg As New PrintDialog()

        If pdlg.ShowDialog(Me) = Windows.Forms.DialogResult.OK Then ' Let user pick printer
            Dim pd As New Printing.PrintDocument()

            pd.PrinterSettings = pdlg.PrinterSettings               ' The document should print how the user set it up in the dialog
            pd.OriginAtMargins = True                               ' Not necessary, but prettier
            AddHandler pd.PrintPage, AddressOf Document_IsPrinting  ' PrintPage is where the "printing" actually occurs
            pd.Print()
        End If
    End Sub

    Private Sub Document_IsPrinting(ByVal sender As Object, ByVal e As Printing.PrintPageEventArgs)
        Dim f As New Font("Arial", 10)
        Dim vOffset As SizeF

        For Each item As String In Me.ListBoxAlpha.Items
            vOffset += e.Graphics.MeasureString(item, f, 300)   ' Get the height of the string as it would be on the page; accumulate so text doesn't overlap
            e.Graphics.DrawString(item, f, Brushes.Black, 0, vOffset.Height + 5)    ' Draw the string on the page
        Next
    End Sub
End Class

Open in new window

untitled.PNG
untitled6.PNG
0
 

Author Closing Comment

by:gs99
ID: 35185134
thanks for your quick reply
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

604 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question