Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Printing in visual basic

Status
Not open for further replies.

kenguru

Programmer
Joined
May 14, 2004
Messages
173
Location
RO
Hi,

I used the printer objectum to print a form in visual basic. Is it possible to print this form first on a virtual way and after viewing that to send to the printer?Like in Word, that first there is a "print preview" and after that we can print the document.
Thank's
Kenguru
 
Yes. You can print to a PictureBox control just like you print to a printer - same methods, etc. You can probably even use the same code as you used to print the form...just replace "Printer" with the PictureBox name. Actually, there's a way to make the same code print to a Form, PictureBox, Printer or any other object that can accept print output:

Code:
Public Sub PrintIt(ByVal PrintTarget as Object)
    PrintTarget.CurrentX = 500
    PrintTarget.CurrentY = 500
    PrintTarget.Print "This is a test."
End Sub

'call Sub like this:

PrintIt Form1.Picture1  'prints to a PictureBox

PrintIt Printer  'prints to the default Printer

If your output spans multiple pages, you can create a control array of picture boxes to do the preview and dynamically load them as needed. If this is something you need, let me know and I'll post some code.

I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson
 
Hi!
Thank's for your answer. I used your test code and the text didn't apeared on the picturebox. What did i make wrong? I used the line form1.show to see the result, but nothing:(
Thank'a
Kenguru
 
Hi!
I realized what is the problem: i would like to print the content of a form on a picturebox which isn't on the main form. But the method PictureBox.Print can only print on an active form, because if i wrote
(i am at the moment on the formmain)
form1.picturebox1.print "test"
form1.show
nothing appears
but if i write (i'am on the formmain)
formmain.picturebox1.print "test"
the text appears
Is there a way to resolve this?
Thank's
Kenguru
 
You can print to a picturebox that is on another form - I do it all the time. To make it work you need to set the target picturebox's AutoRedraw property to True.

I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson
 
Can we move this to the Visual Basic 5 & 6 forum? This one is for database related questions.

Thanks.
Chip H.


____________________________________________________________________
Click here to learn Ways to help with Tsunami Relief
If you want to get the best response to a question, please read FAQ222-2244 first
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top