Real Software Forums
http://forums.realsoftware.com/

Printing
http://forums.realsoftware.com/viewtopic.php?f=10&t=74
Page 1 of 1

Author:  Synner [ Sat Oct 01, 2005 9:55 pm ]
Post subject:  Printing

Hello all...

I need some help, since I'm apparently slow and just can't figure this out...

I want to print the contents of a listbox. Can that be done? Can someone point me in the right direction (or provide a snippet of code?)....

Thanks.

Author:  Charlie Boisseau [ Sun Oct 02, 2005 3:58 am ]
Post subject: 

Really quick and dirty:
Dim g As Graphics = OpenPrinterDialog ()
Dim StartHeight As Integer = 100

If g<> Nil then
For y As Integer = 0 to Listbox1.ListCount - 1
For x As Integer = 0 to Listbox1.ColumnCount - 1

g.DrawString ListBox1.Cell(y, x), (x*ListBox1.Column(x).WidthActual), (y*30)+StartHeight
Next
Next
End if

Author:  Steve Garman [ Sun Oct 02, 2005 6:56 am ]
Post subject: 

Charlie Boisseau wrote:
Really quick and dirty:


Or, if you're looking for something a bit more considered, there's a nice Listbox printer module at CallerID.com

Author:  Synner [ Sun Oct 02, 2005 1:55 pm ]
Post subject: 

Charlie Boisseau wrote:
Really quick and dirty:
Dim g As Graphics = OpenPrinterDialog ()
Dim StartHeight As Integer = 100

If g<> Nil then
For y As Integer = 0 to Listbox1.ListCount - 1
For x As Integer = 0 to Listbox1.ColumnCount - 1

g.DrawString ListBox1.Cell(y, x), (x*ListBox1.Column(x).WidthActual), (y*30)+StartHeight
Next
Next
End if


Charlie,

Thanks so much.... a quick question...

I'm losing my first and third column in the printing process..... It's printing columns 2 and 3, but not 1 and 4. Is there something I should be tweaking in your snippet?

Thanks again. I truly appreciate this!

Author:  Charlie Boisseau [ Sun Oct 02, 2005 3:23 pm ]
Post subject: 

It works for me. Maybe check your column widths are ok. Also, you may want to check pagesetup info before printing. You should read all the docs on the Language ref.

Author:  Synner [ Sun Oct 02, 2005 4:54 pm ]
Post subject: 

Charlie Boisseau wrote:
It works for me. Maybe check your column widths are ok. Also, you may want to check pagesetup info before printing. You should read all the docs on the Language ref.


I'm sorry. I'm new at this, so forgive my ignorance.

What should I check about the column widths? My column widths are 35,110,110 and 380.

All the data appears in the list box itself.....

What am I doing wrong?

Author:  Jennifer [ Sun Oct 02, 2005 6:12 pm ]
Post subject: 

I don't know if this is any better. It does basically the same thing in a slightly different way. We just upgraded to XP x64, so our printer doesn't work, but it worked Ok when sending output to a edit field.

dim s as String
dim i, j as integer
dim g as Graphics

j = ListBox1.ListCount - 1

for i = 0 to j
//Single column listBox
's = s + ListBox1.List(i) + chr(10)
//Multi-column listBox
s = s + ListBox1.Cell(i, -1) + chr(10)
next i
'Send s to printer as graphics object

Author:  Jennifer [ Sun Oct 02, 2005 8:59 pm ]
Post subject: 

I finally found it. The code I used to print is this:

dim g as graphics
g = openPrinter()
g.textFont = "Courier"
g.textSize = 8
g.DrawString s, 50, 50


In this case, the string "s" is the source. I'm not sure how this works with word wrap. That might be what the two optional values handle.

Author:  Jym [ Thu Oct 06, 2005 1:32 am ]
Post subject: 

It doesn't work for word wrap as you must stipulate at what width the wrap takes place at.

You don't need a printer to test your prints, Think of the paper as a canvas, so if you draw to canvas instead of the paper, you'll know exactly what it looks like.

Author:  Synner [ Thu Oct 06, 2005 6:55 pm ]
Post subject: 

Jen's code works, but where a space should be between the columns, I get a litte 'square' box instead....

So, now what am I doing wrong? Is there a way to fix that?

Thanks in advance.

Author:  Jennifer [ Thu Oct 06, 2005 7:20 pm ]
Post subject: 

Drawing to a canvas is a good idea. I will try that. I hope to have a new printer soon.

If you are getting a box that means your printer is not recoqnizing the chr(10) code. Try endOfLine. It might even be something diferent on Mac. I can't remember for sure.

Author:  Jennifer [ Thu Oct 06, 2005 7:23 pm ]
Post subject: 

Between columns? That may be something different, but try it just to see. If it is the Chr(10) causing problems, I would expect to see a square at the end of each row.

Author:  Jym [ Fri Oct 07, 2005 12:28 pm ]
Post subject: 

Speaking from a Win32 box, a square box could be numerous things, but generally it means it's a charactor that the Font you are using doesn't have. Windows for example uses chr(13) +chr(10) for a line return and maybe one or the other is causing it to line return and the other is giving you a square. What you can do is replace all the different line returns with EndOfLine before printing.

You need to do it in this order or you will get a double EndOfLine for the chr(13) + chr(10)

replaceAll(string_to_be_printed, chr(13) + chr(10), EndOfLine)
replaceAll(string_to_be_printed, chr(13), EndOfLine)
replaceAll(string_to_be_printed, chr(10), EndOfLine)

Page 1 of 1 All times are UTC - 5 hours
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/