ucla11
asked on
How do print the contents of a listbox
I have a print on program and it needs to print the contents of listbox called lstAnwsers
http://www.vb-helper.com/howto_align_printed_listbox.html
ASKER
I get an error message saying 'Graphics' is not a member of 'System.EventArgs'. is this code for VB 6 , I am using VB.net
ASKER
here is print code for previous comment
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrint.Click
Dim txt As String = ""
For Each item As String In lstAnwsers.Items
txt &= vbCrLf & item
Next item
txt = txt.Substring(vbCrLf.Lengt h)
Using the_font As New Font("Times New Roman", 20, _
FontStyle.Regular, GraphicsUnit.Point)
' Left aligned.
Using sf As New StringFormat()
Dim rect As New Rectangle(1 * 100, 100, 150, 250)
sf.Alignment = StringAlignment.Near
e.Graphics.DrawRectangle(P ens.Red, rect)
e.Graphics.DrawString(txt, the_font, Brushes.Red, _
rect, sf)
End Using
' Centered.
Using sf As New StringFormat()
Dim rect As New Rectangle(3 * 100, 100, 150, 250)
sf.Alignment = StringAlignment.Center
e.Graphics.DrawRectangle(P ens.Green, rect)
e.Graphics.DrawString(txt, the_font, Brushes.Green, _
rect, sf)
End Using
' Right aligned.
Using sf As New StringFormat()
Dim rect As New Rectangle(5 * 100, 100, 150, 250)
sf.Alignment = StringAlignment.Far
e.Graphics.DrawRectangle(P ens.Blue, rect)
e.Graphics.DrawString(txt, the_font, Brushes.Blue, _
rect, sf)
End Using
End Using
e.HasMorePages = False
End Sub
End Class
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrint.Click
Dim txt As String = ""
For Each item As String In lstAnwsers.Items
txt &= vbCrLf & item
Next item
txt = txt.Substring(vbCrLf.Lengt
Using the_font As New Font("Times New Roman", 20, _
FontStyle.Regular, GraphicsUnit.Point)
' Left aligned.
Using sf As New StringFormat()
Dim rect As New Rectangle(1 * 100, 100, 150, 250)
sf.Alignment = StringAlignment.Near
e.Graphics.DrawRectangle(P
e.Graphics.DrawString(txt,
rect, sf)
End Using
' Centered.
Using sf As New StringFormat()
Dim rect As New Rectangle(3 * 100, 100, 150, 250)
sf.Alignment = StringAlignment.Center
e.Graphics.DrawRectangle(P
e.Graphics.DrawString(txt,
rect, sf)
End Using
' Right aligned.
Using sf As New StringFormat()
Dim rect As New Rectangle(5 * 100, 100, 150, 250)
sf.Alignment = StringAlignment.Far
e.Graphics.DrawRectangle(P
e.Graphics.DrawString(txt,
rect, sf)
End Using
End Using
e.HasMorePages = False
End Sub
End Class
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.