Link to home
Start Free TrialLog in
Avatar of ucla11
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
Avatar of sunnycoder
sunnycoder
Flag of India image

Avatar of ucla11
ucla11

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
Avatar of ucla11

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.Length)

        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(Pens.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(Pens.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(Pens.Blue, rect)
                e.Graphics.DrawString(txt, the_font, Brushes.Blue, _
                    rect, sf)
            End Using
        End Using

        e.HasMorePages = False
    End Sub
End Class
ASKER CERTIFIED SOLUTION
Avatar of sunnycoder
sunnycoder
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial