Solved

How do print the contents of a  listbox

Posted on 2008-10-21
4
607 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
[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
  • 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

The greatest common divisor (gcd) of two positive integers is their largest common divisor. Let's consider two numbers 12 and 20. The divisors of 12 are 1, 2, 3, 4, 6, 12 The divisors of 20 are 1, 2, 4, 5, 10 20 The highest number among the c…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

733 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