Solved

How do print the contents of a  listbox

Posted on 2008-10-21
4
602 Views
Last Modified: 2012-05-05
I have a print on program and it needs to print the contents of listbox called lstAnwsers
0
Comment
Question by:ucla11
  • 2
  • 2
4 Comments
 
LVL 45

Expert Comment

by:sunnycoder
ID: 22773160
0
 

Author Comment

by:ucla11
ID: 22773449
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
0
 

Author Comment

by:ucla11
ID: 22773460
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
0
 
LVL 45

Accepted Solution

by:
sunnycoder earned 250 total points
ID: 22773489
>I get an error message saying 'Graphics' is not a member of 'System.EventArgs'.
Its a member of System.Drawing
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
Prime numbers are natural numbers greater than 1 that have only two divisors (the number itself and 1). By “divisible” we mean dividend % divisor = 0 (% indicates MODULAR. It gives the reminder of a division operation). We’ll follow multiple approac…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

759 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now