Improve company productivity with a Business Account.Sign Up
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
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
Open in new window
Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.
Have a better answer? Share it in a comment.
Please enter a first name
Please enter a last name
Must be at least 4 characters long.
Join and Comment
Be seen. Boost your question’s priority for more expert views and faster solutions