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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Printing a picture box. 3

Status
Not open for further replies.

peekay

Programmer
Oct 11, 1999
324
ZA
How do I print the contents of a picture box to the printer. It seems that the PrintForm method only prints a form to a printer and not a picture box. PK Odendaal
and pko@942.co.za
 
I have received so many comments for which I am very grateful.

I must elaborate on my problem. I am programmatically drawing lines, circles etc. - representing a structure to a picture box where I manipulate the vectors with other statements. I then wish to print this vector picture to a printer.

In this case it was easy for me to redraw those vectors on a form and use the printform method, but the Printform is inherently of a low resolution and I was trying to output high quality structural drawings.

The alternative I had was to plot the vectors to the printer, but that would entail writing a very large routine to do that.

So the next option that presents itself is to define an object and plot these vectors to the object. That works well if one plots to a picture box or a form as an object, but it does not work properly when the object is a printer. I get the directions of the arrows wrong, the text in the wrong places and the vectors upside down whilst the text is upright.

There will be so many changes to my PlotToObject routine that I will virtually have to rewrite it. (it is a very involved routine because I plot the members of the structure, their numbers (in boxes), the nodes and their numbers in circles, the forces and loads etc.)

I did not say that the function by strongm was wrong. I think it would be applicable, but I have not been able to get it to work.

PK Odendaal
and pko@942.co.za
 

So then you need the
[tt]
Printer.PaintPicture Picture1.Image, 0, 0
Printer.EndDoc
[/tt]
to print the contents of the picture box correctly.

Good Luck

 
vb5prgrmr

I still cannot get it to work. It only prints the background. According to the helpfile this method only works to print : .. Draws the contents of a graphics file (.bmp, .wmf, .emf, .cur, .ico, or .dib) on a Form, PictureBox, or Printer.
I have no intrinsic image on this picture box and I think that is the reason why it does not print. PK Odendaal
and pko@942.co.za
 
Are you actually drawing the lines on the form with graphics methods, or are you drawing lines and shapes in the picturebox using the line control and shape control?

Robert
 

I started a new project and added a picture box and a command button. I changed the autoredraw property of the picture box to = true. I then tried the following code...
[tt]
Option Explicit

Private Sub Command1_Click()
Picture1.Line (100, 100)-(1000, 1000), RGB(255, 0, 0)
Me.WindowState = vbMinimized
Me.WindowState = vbNormal
Printer.PaintPicture Picture1.Image, 0, 0
Printer.EndDoc
End Sub
[/tt]
(with and without the changes in window state)
I printed to an HP 4050N, 8100, 9000 all had the line printed.

peekay, are you sure that you are using the .Image?

Good Luck

 
As vb5prgrmr says, it looks like you would need the .Image variant of the code. However, now that we better understanding what you are trying to achieve, I feel it worth mentioning that the picturebox will also suffer resolution problems. So, how do we get around this? And how do we limit the amount of rewriting that you would need to do?

A quick question. Are you using VB's drawing functions, or the GDI API?

If the latter then one possibility would be to capture the plotting to a memory metafile, and then play the metafile to the picturebox's hdc for screen display and to the printer's hdc for printing...
 
Are you actually drawing the lines on the form with graphics methods, or are you drawing lines and shapes in the picturebox using the line control and shape control? - I am drawing lines and circles with the line and circle methods on the picture box.

I do not think the autoredraw property has any effect on what it prints to the printer.It has got to do whether the image on the pricure box is still visible after a form minimise event. I had to set the autoredraw property to false to enable me to rotate the structure in the picture box in 3D in real time. With it set to true the rotation is very slow and discrete and it uses too much memory.

I do not know what is meant by the image variant of the code. As I understand it a picture box may contain an image, but I do not think that is the case with my application. i.e. the picture property is (none).

With regard to the resolution : On the picture box the resolution is fine - in fact it depends on the resolution of the video card, but I find that when doing a printform method the resolution on the printer is too low for a neat drawing. PK Odendaal
and pko@942.co.za
 

Para 1:If you look at my code you will see that I am using the line method of the picture box.

Para 2:

Para 3:Look at our posts carefully please

Para 4:

 
I got it right by putting the autoredraw property to true.
The quality however is the same as for Printform.
I wish to thank everyone for the contributions they have made - and a star for vb5prgrmr for the Persistence of his Active(x) help. PK Odendaal
and pko@942.co.za
 
>The quality however is the same as for Printform

Exactly the point I made.
 

You can increase the quality by increasing the size of the image (doubling it) and using the optional parameters width1 and height1 to compress it in half (back to origional size), and all of this can be done in the background.

Good Luck

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top