From: Webbiz on
On Fri, 06 Nov 2009 20:33:06 -0300, Eduardo <mm(a)mm.com> wrote:

>Webbiz escribi�:
>
>> When the code gets to Printer.PaintPicture frmMain.Picture1, I get an
>> "Invalid Picture" error.
>
>frmMain.Picture1.Image


Misunderstood.

You must have meant...

Printer.PaintPicture frm.Picture1.Image

That prints the form.

Thanks.
Webbiz


From: Webbiz on
On Fri, 06 Nov 2009 20:33:06 -0300, Eduardo <mm(a)mm.com> wrote:

>Webbiz escribi�:
>
>> When the code gets to Printer.PaintPicture frmMain.Picture1, I get an
>> "Invalid Picture" error.
>
>frmMain.Picture1.Image

This is the line I have...

Printer.PaintPicture frm.Picture1.Image, 0, 0

....not Printer.PaintPicture frm.Picture1

I was only pointing out what line the error was occuring.

Anyway, this part works now and I don't know why.

Public Sub PrintTheForm(ByVal frm As Form)

Dim WidthForm As Long
Dim HeightForm As Long

WidthForm = frm.ScaleX(frm.Width, frm.ScaleMode, vbPixels)
HeightForm = frm.ScaleY(frm.Height, frm.ScaleMode, vbPixels)

frm.Picture1.Visible = False
frm.Picture1.AutoRedraw = True
frm.Picture1.Move 0, 0, frm.ScaleX(frm.Width, vbTwips,
frm.ScaleMode), _
frm.ScaleY(frm.Height, vbTwips, frm.ScaleMode)

Call BitBlt(frm.Picture1.hDC, 0, 0, WidthForm, HeightForm, _
GetWindowDC(frm.hwnd), 0, 0, vbSrcCopy)

Printer.PaintPicture frm.Picture1.Image, 0, 0

Printer.EndDoc

End Sub


====================

Now I'm going to use the other code provided that allows printing to
fill the page to see if I can get this from chopping off the end of
the form in the printout.

:-)

Webbiz


From: Webbiz on
Okay, this will work just fine.

Since the only thing that is going to be printed is the forms, and
they are all the same width (too long for portrait mode), rather than
give a choice to shrink or landscape, I'm just going to default to
landscape for the purpose of printing these forms.

At least for now, until I get a better handle on shrinking the picture
being printed.

Here is my final form printing code:

Public Sub PrintTheForm(ByVal frm As Form)

Dim WidthForm As Long
Dim HeightForm As Long

WidthForm = frm.ScaleX(frm.Width, frm.ScaleMode, vbPixels)
HeightForm = frm.ScaleY(frm.Height, frm.ScaleMode, vbPixels)

frm.Picture1.Visible = False
frm.Picture1.AutoRedraw = True
frm.Picture1.Move 0, 0, frm.ScaleX(frm.Width, vbTwips,
frm.ScaleMode), _
frm.ScaleY(frm.Height, vbTwips, frm.ScaleMode)

Call BitBlt(frm.Picture1.hDC, 0, 0, WidthForm, HeightForm, _
GetWindowDC(frm.hwnd), 0, 0, vbSrcCopy)

Printer.Orientation = vbPRORLandscape
Printer.PaintPicture frm.Picture1.Image, 0, 0

Printer.EndDoc
Printer.Orientation = vbPRORPortrait

End Sub


Thanks.

Webbiz
From: Eduardo on
Webbiz escribi�:

> I had to modify it slightly since the printform routine needs to be in
> a module. Otherwise, I'd have to add it to every form rather than in
> just one place.
>
> Public Sub PrintTheForm(ByVal frm As Form)
>
> Dim WidthForm As Long
> Dim HeightForm As Long
>
> WidthForm = frm.ScaleX(frm.Width, frm.ScaleMode, vbPixels)
> HeightForm = frm.ScaleY(frm.Height, frm.ScaleMode, vbPixels)
>
> frm.Picture1.Visible = False
> frm.Picture1.AutoRedraw = True
> frm.Picture1.Move 0, 0, frm.ScaleX(frm.Width, vbTwips,
> frm.ScaleMode), _
> frm.ScaleY(frm.Height, vbTwips, frm.ScaleMode)
>
> Call BitBlt(frm.Picture1.hDC, 0, 0, WidthForm, HeightForm, _
> GetWindowDC(frm.hwnd), 0, 0, vbSrcCopy)
> Printer.PaintPicture frm.Picture1.Image, 0, 0
> Printer.EndDoc
>
> End Sub
>
>
> The problem, however, is that it is not printing everything that is on
> the form. The picturebox is blank. The grids are blank. The buttons
> are not visible, nor anything much except the outline of the form
> itself.
>
> Also, part of the next to last command...
>
> Printer.PaintPicture frm.Picture1.Image, 0, 0
>
> ...also shows up on the printout as "1.Image,0,0" in text form.
>
> What am I missing?

I don't know, I see everything printed here (using Vista).

Please remove the picturebox from the form, it won't be necessary
anymore since I add a temporary picturebox in the printing routine
(assuming you use VB6 and not 5).

Please paste this in the module and check if it works:
(If it doesn't work I'll try something else)

Private Declare Function BitBlt Lib "gdi32" _
(ByVal hDCDest As Long, ByVal XDest As Long, _
ByVal YDest As Long, ByVal nWidth As Long, _
ByVal nHeight As Long, ByVal hDCSrc As Long, _
ByVal XSrc As Long, ByVal YSrc As Long, _
ByVal dwRop As Long) As Long

Private Declare Function GetWindowDC Lib _
"user32" (ByVal hwnd As Long) As Long

Public Sub PrintTheForm(ByVal frm As Form)
Dim WidthForm As Long
Dim HeightForm As Long
Dim iPicture1 As Control

WidthForm = frm.ScaleX(frm.Width, frm.ScaleMode, vbPixels)
HeightForm = frm.ScaleY(frm.Height, frm.ScaleMode, vbPixels)

Set iPicture1 = frm.Controls.Add("VB.PictureBox", "PictureTmp")
iPicture1.BorderStyle = 0
iPicture1.AutoRedraw = True
iPicture1.Move 0, 0, frm.ScaleX(frm.Width, _
vbTwips, frm.ScaleMode), frm.ScaleY(frm.Height, _
vbTwips, frm.ScaleMode)

Call BitBlt(iPicture1.hDC, 0, 0, WidthForm, HeightForm, _
GetWindowDC(frm.hwnd), 0, 0, vbSrcCopy)
Printer.PaintPicture iPicture1.Image, 0, 0
Printer.EndDoc
frm.Controls.Remove "PictureTmp"
End Sub
From: Eduardo on
Webbiz escribi�:
> On Fri, 06 Nov 2009 20:33:06 -0300, Eduardo <mm(a)mm.com> wrote:
>
>> Webbiz escribi�:
>>
>>> When the code gets to Printer.PaintPicture frmMain.Picture1, I get an
>>> "Invalid Picture" error.
>> frmMain.Picture1.Image
>
>
> Misunderstood.
>
> You must have meant...
>
> Printer.PaintPicture frm.Picture1.Image

Yes.

I was pointing that with 'frm.Picture1' you are just referencing the
picturebox or its default property, that is 'Picture', and you need the
property 'Image'.