Printing items in a listbox in VB.NET

C

Carlo

From the answer below I am now not getting an error! Great!
But it is now printing the items one on top of each other.
Any ideas?

Thanks


Hi
I'm trying to print the items in a listbox with the code below but
when I click on print I get
"An unhandled exception of type 'System.ArgumentOutOfRangeException'
occurred in system.windows.forms.dll

Additional information: Specified argument was out of the range of
valid values"

Firstly, what does the message mean and secondly what am I doing wrong
in the coding below. More importantly how do I fix it?
Thanks
Carlob1


Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object,
ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles
PrintDocument1.PrintPage
Dim max, n As Integer
max = lstTally.Items.Count
For n = 1 To max
e.Graphics.DrawString(lstTally.Items(n), New Font("arial",
40, FontStyle.Regular), Brushes.Black, 200, 200)
Next
End Sub

Private Sub MenuItem1_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles MenuItem1.Click
PrintDocument1.Print()
txtInput.Focus()
txtInput.SelectAll()
End Sub
Post a follow-up to this message

Message 2 in thread
From: Ken Tucker [MVP] ([email protected])
Subject: Re: Printing items in a listbox


View this article only
Newsgroups: microsoft.public.dotnet.languages.vb
Date: 2004-03-22 20:08:19 PST


Hi,

The first item is 0.
For n = 0 To max-1
e.Graphics.DrawString(lstTally.Items(n), New Font("arial",
40, FontStyle.Regular), Brushes.Black, 200, 200)
Next

Ken
------------
Carlo said:
Hi
I'm trying to print the items in a listbox with the code below but
when I click on print I get
"An unhandled exception of type 'System.ArgumentOutOfRangeException'
occurred in system.windows.forms.dll

Additional information: Specified argument was out of the range of
valid values"

Firstly, what does the message mean and secondly what am I doing wrong
in the coding below. More importantly how do I fix it?
Thanks
Carlob1


Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object,
ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles
PrintDocument1.PrintPage
Dim max, n As Integer
max = lstTally.Items.Count
For n = 1 To max
e.Graphics.DrawString(lstTally.Items(n), New Font("arial",
40, FontStyle.Regular), Brushes.Black, 200, 200)
Next
End Sub

Private Sub MenuItem1_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles MenuItem1.Click
PrintDocument1.Print()
txtInput.Focus()
txtInput.SelectAll()
End Sub
Post a follow-up to this message

Message 3 in thread
From: Carlo ([email protected])
Subject: Re: Printing items in a listbox


View this article only
Newsgroups: microsoft.public.dotnet.languages.vb
Date: 2004-03-24 09:38:21 PST


Thanks very much Ken
Just one problem - it prints all the items in the list box on top of
one another! How do I get a cariage return between each item when
printing?
Thanks
carlo
 
K

Ken Tucker [MVP]

Hi,

You are drawing everything at the same spot. Try increasing the y
coordinate with each item.

For n = 0 To max-1
e.Graphics.DrawString(lstTally.Items(n), New Font("arial", 40,
FontStyle.Regular), Brushes.Black, 200, 200 + n * 45)
Next

Ken
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top