Solved

How do print the contents of a  listbox

Posted on 2008-10-21
4
603 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Library to convert HTML to PDF. 8 57
Setting runtime form location 4 30
Want to create a userform that looks like the image provided 10 44
VS.net 2010 11 23
A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

895 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

12 Experts available now in Live!

Get 1:1 Help Now