Printing a form with a picture

I’m using a website’s Post API to get an image returned in an htmlviewer. I want to print a form with some text and the image in the htmlviewer. Since htmlviewer.drawinto doesn’t seem to work, I’m using the trick of putting the htmlviewer into a hidden window and using window.drawinto to get the image into the printer graphics.

PrintWindow.PrintHTMLViewer.LoadPage(s, f) PrintWindow.DrawInto(g,71,62)

All of the other elements of the print output work fine (g.DrawRect, g.Drawstring, etc.).

The problem I’m having is that the image is blank the first, and only the first, time I try to print the form. The rest of the form prints fine, only the image is blank. But if I immediately print again, it works correctly the second time.

Thanks in advance for any ideas you might have that I could try.

OK, I’ve figured out that the resulting printout always contains the previous contents of the PrintHTMLViewer. It seems that the LoadPage starts and the code continues and executes the DrawInto before the data is returned. Does that sound right?

I’m executing the above code in a Print menu handler, so I don’t know how to check for a completion event before executing the DrawInto.

Is there a way to wait for the completion and then continuing the code within a menu handler?

Instead of an HTMLViewer, use an HTTPSocket to retrieve the image data directly into your code. Create a picture and use Picture.FromData to put the data into the picture. Now you can use Graphics.DrawPicture to print the picture directly.

Thanks, Tim. I’ve taken a look at this and it seems like this will work but I’m unclear how to use HTTPSocket.Post. Here’s some sample data that I’m sending as a string using HTTPViewer.LoadPage:


Hex Name UWP Remarks {Ix} (Ex) [Cx] N B Z PBG W A Stellar ---- -------------------- --------- --------------------------- ------ ------- ------ ----- - - --- -- -- -------------- 0101 Zeycude C430698-9 De Na Ni Po { -1 } (C53-1) [6559] - - - 613 8 Zh K9 V 0302 Reno C4207B9-A De He Na Po Pi { 1 } (C6A+1) [886B] - - - 603 12 Aw G8 V M1 V 0503 Errere B563664-B Ni Ri Cp { 2 } (956+2) [4839] - Z - 910 9 Aw M1 V M4 V <?xml version="1.0"?> Avalon 0202 0302 0402 0503 0504 0404 0304 0203 Art's Worlds [/code]

How would you suggest that I send this using HTTPSocket?

Construct a dictionary for the field name/value pairs and pass that to SetFormData.