Flip Vertical and Print

Printer.PaintPicture Picture1.Picture, 0, Picture1.ScaleHeight, _
Picture1.ScaleWidth, -Picture1.ScaleHeight, 0, 0, Picture1.ScaleWidth, _
Picture1.ScaleHeight, vbSrcCopy

I have seen this code in various places on the web but it does not seem to work. I am trying to get a label to flip to the vertical. Any help would be appreciated.



Not sure what you mean by "trying to get a label to flip". If you have a label control embedded in your source picture box, it is ignored by PaintPicture.

The PaintPicture method operates only with the Picture property of the supplied PictureBox control. So, if you haven't set that property, there's nothing to paint from. Even if you try to fake it out with the old "Picture1.Print" trick, it still ignores it.

You could try to get fancy with the Win32 API calls to grab screen pixels, save it as a bitmap, then reload it into the picture box's Picture property, but what a pain that would be. I don't really have any suggestions other than digging into the Win32 API.

Sorry, and good luck!

Update on what I posted. I was bored, so I figured I'd do some science experiments using different combinations of image, picture box, and the Picture and Image properties.

Imagine my surprise when I was able to get a Picture Box to flip a picture, and after I had printed text on it! It showed the text as flipped too!

Here's how it works:
1. Create a form.
2. Create a PictureBox control.
3. Load a picture into the picture box. (At design time, set the "Picture" property to a jpg or bmp or whatever; at run-time use the LoadPicture function)
4. Set the "AutoRedraw" property on the picture box to "True". This is important, as it causes the Image property to become a handle to a persistent graphics area in memory.
5. Use the PictureBox1.Print method to put some text on the picture box. You'll have to do some formatting yourself to make it look right.
6. Use this code to send it (upside-down) to the printer:

Printer.PaintPicture Me.Picture1.Image, Me.Picture1.Width, Me.Picture1.Height, -Me.Picture1.Width, -Me.Picture1.Height

Note that there is NO REFERENCE to hDc handles, Win32 API calls, screen contexts or any of the uglier stuff. Granted, it's still complicated, but very do-able with native VB6.

Note also that the PaintPicture command references the Image property of the Picture Box, NOT the Picture property.

Now obviously, you can have all sorts of fun with this. For instance, Use a pair of picture boxes to mix-and-match upside-down and right-side up by using Pic1.Print, then set the Pic2.Image to the invert of it, then Pic2.Print, then send to whole mess to the printer.

However, there is an important caveat...the printer will ONLY print what is visible inside the PictureBox control.

Good luck again, and have fun!

This article has been dead for over six months. Start a new discussion instead.