Solved

How do print the contents of a  listbox

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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

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…
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…
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…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

691 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