From: albertleng on
My project needs to print a large PictureBox which during runtime only
part of it is shown (as it's too large,
width=4000 pixels and height= 2000 pixels) and to see the rest of the
picturebox, user needs to scroll through
the vertical and horizontal bars. On top of the picturebox, there are
many controls which are loaded and positioned
by user on run-time. Those include lines, labels, another picturebox
with image and user-defined controls.

Now, i need to write a print function which will print that picturebox
to not too many pages in A4 size or A3 size.
Not too many means less than 5 for both paper size.
My questions:

1) How can i print the whole picturebox with all its contents and go
to next printing page until the whole PictureBox is
printed? I tried using the following code but
(i)The image of picturebox inside that picture box and user-defined
control are not printed whereas others
are printed. Why is that so? How can i print the picturebox
including both the "un-printed"?
(ii) Even i can print out the picturebox, only the part where
the picturebox is shown is printed. How can i print
the whole picturebox including those parts which needs scrolling
to reach?

Private Sub CmdPrint_Click()
Dim rv As Long

'Picture1 is the picturebox to be printed.
Picture1.SetFocus ' So that the button doesn't look pressed
Picture2.AutoRedraw = True

Picture2.Height = Picture1.Height
Picture2.Width = Picture1.Width
rv = SendMessage(Picture1.hwnd, WM_PAINT, Picture2.hDC, 0)
rv = SendMessage(Picture1.hwnd, WM_PRINT, Picture2.hDC, _
PRF_CHILDREN + PRF_CLIENT + PRF_OWNED)
Picture2.Height = Picture1.Height
Picture2.Width = Picture1.Width


Picture2.Picture = Picture2.Image
Picture2.AutoRedraw = False
Printer.Orientation = vbPRORLandscape ' 2
Printer.Print ""
Printer.PaintPicture Picture2.Picture, 0, 0
Printer.CurrentY = Picture2.Height + 200 ' get below image
Printer.Print "Text1 on the same page as the image!"
Printer.EndDoc

CmdPrint.SetFocus ' Return Focus
End Sub

2) I also tried using the Print Screen method which during printing,
the scrollbar will move and my program calls
the printscreen and print the picturebox's area which is exposed.
The scrollbar will move again and the same process
repeats itself. This has a drawback which the user will need to
print a lot of pages (~20pages) which are too many and
it's hard to ensure each printed page is correctly printed in which
they all can be joint together after printing.
For this way, i use the idea in
http://support.microsoft.com/kb/q161299/
i use

'Me is the captured PictureBox' area.
Set Picture1.Picture = CaptureClient(Me) 'Picture1 is an invisible
PictureBox for printing.
PrintPictureToFitPage Printer, Picture1.Picture
Printer.EndDoc
Set Picture1.Picture = Nothing

Please help. I'm desperate and really truggling.
From: "Bill McCarthy" TPASoft.com Are Identity on
Hi albert,

Sounds like you want to create another bitmap and copy to that using
StretchBlt.



"albertleng" <albertleng(a)gmail.com> wrote in message
news:d78d0b92-55a0-45f5-8d73-b42e548f349d(a)x6g2000pre.googlegroups.com...
> My project needs to print a large PictureBox which during runtime only
> part of it is shown (as it's too large,
> width=4000 pixels and height= 2000 pixels) and to see the rest of the
> picturebox, user needs to scroll through
> the vertical and horizontal bars. On top of the picturebox, there are
> many controls which are loaded and positioned
> by user on run-time. Those include lines, labels, another picturebox
> with image and user-defined controls.
>
> Now, i need to write a print function which will print that picturebox
> to not too many pages in A4 size or A3 size.
> Not too many means less than 5 for both paper size.
> My questions:
>
> 1) How can i print the whole picturebox with all its contents and go
> to next printing page until the whole PictureBox is
> printed? I tried using the following code but
> (i)The image of picturebox inside that picture box and user-defined
> control are not printed whereas others
> are printed. Why is that so? How can i print the picturebox
> including both the "un-printed"?
> (ii) Even i can print out the picturebox, only the part where
> the picturebox is shown is printed. How can i print
> the whole picturebox including those parts which needs scrolling
> to reach?
>
> Private Sub CmdPrint_Click()
> Dim rv As Long
>
> 'Picture1 is the picturebox to be printed.
> Picture1.SetFocus ' So that the button doesn't look pressed
> Picture2.AutoRedraw = True
>
> Picture2.Height = Picture1.Height
> Picture2.Width = Picture1.Width
> rv = SendMessage(Picture1.hwnd, WM_PAINT, Picture2.hDC, 0)
> rv = SendMessage(Picture1.hwnd, WM_PRINT, Picture2.hDC, _
> PRF_CHILDREN + PRF_CLIENT + PRF_OWNED)
> Picture2.Height = Picture1.Height
> Picture2.Width = Picture1.Width
>
>
> Picture2.Picture = Picture2.Image
> Picture2.AutoRedraw = False
> Printer.Orientation = vbPRORLandscape ' 2
> Printer.Print ""
> Printer.PaintPicture Picture2.Picture, 0, 0
> Printer.CurrentY = Picture2.Height + 200 ' get below image
> Printer.Print "Text1 on the same page as the image!"
> Printer.EndDoc
>
> CmdPrint.SetFocus ' Return Focus
> End Sub
>
> 2) I also tried using the Print Screen method which during printing,
> the scrollbar will move and my program calls
> the printscreen and print the picturebox's area which is exposed.
> The scrollbar will move again and the same process
> repeats itself. This has a drawback which the user will need to
> print a lot of pages (~20pages) which are too many and
> it's hard to ensure each printed page is correctly printed in which
> they all can be joint together after printing.
> For this way, i use the idea in
> http://support.microsoft.com/kb/q161299/
> i use
>
> 'Me is the captured PictureBox' area.
> Set Picture1.Picture = CaptureClient(Me) 'Picture1 is an invisible
> PictureBox for printing.
> PrintPictureToFitPage Printer, Picture1.Picture
> Printer.EndDoc
> Set Picture1.Picture = Nothing
>
> Please help. I'm desperate and really truggling.

From: Eduardo on
My idea is to use Printer.PaintPicture to copy each section of the
picturebox separately.

Printer.PaintPicture Picture1.Image, x, y, width, height

where x, y, width and height define the part to be printed in that page.

Then:

Printer.NewPage

and do the same for others parts of the pic.

And don't forget:

Printer.EndDoc

I think this should work.

"albertleng" <albertleng(a)gmail.com> escribi� en el mensaje
news:d78d0b92-55a0-45f5-8d73-b42e548f349d(a)x6g2000pre.googlegroups.com...
> My project needs to print a large PictureBox which during runtime only
> part of it is shown (as it's too large,
> width=4000 pixels and height= 2000 pixels) and to see the rest of the
> picturebox, user needs to scroll through
> the vertical and horizontal bars. On top of the picturebox, there are
> many controls which are loaded and positioned
> by user on run-time. Those include lines, labels, another picturebox
> with image and user-defined controls.
>
> Now, i need to write a print function which will print that picturebox
> to not too many pages in A4 size or A3 size.
> Not too many means less than 5 for both paper size.
> My questions:
>
> 1) How can i print the whole picturebox with all its contents and go
> to next printing page until the whole PictureBox is
> printed? I tried using the following code but
> (i)The image of picturebox inside that picture box and user-defined
> control are not printed whereas others
> are printed. Why is that so? How can i print the picturebox
> including both the "un-printed"?
> (ii) Even i can print out the picturebox, only the part where
> the picturebox is shown is printed. How can i print
> the whole picturebox including those parts which needs scrolling
> to reach?
>
> Private Sub CmdPrint_Click()
> Dim rv As Long
>
> 'Picture1 is the picturebox to be printed.
> Picture1.SetFocus ' So that the button doesn't look pressed
> Picture2.AutoRedraw = True
>
> Picture2.Height = Picture1.Height
> Picture2.Width = Picture1.Width
> rv = SendMessage(Picture1.hwnd, WM_PAINT, Picture2.hDC, 0)
> rv = SendMessage(Picture1.hwnd, WM_PRINT, Picture2.hDC, _
> PRF_CHILDREN + PRF_CLIENT + PRF_OWNED)
> Picture2.Height = Picture1.Height
> Picture2.Width = Picture1.Width
>
>
> Picture2.Picture = Picture2.Image
> Picture2.AutoRedraw = False
> Printer.Orientation = vbPRORLandscape ' 2
> Printer.Print ""
> Printer.PaintPicture Picture2.Picture, 0, 0
> Printer.CurrentY = Picture2.Height + 200 ' get below image
> Printer.Print "Text1 on the same page as the image!"
> Printer.EndDoc
>
> CmdPrint.SetFocus ' Return Focus
> End Sub
>
> 2) I also tried using the Print Screen method which during printing,
> the scrollbar will move and my program calls
> the printscreen and print the picturebox's area which is exposed.
> The scrollbar will move again and the same process
> repeats itself. This has a drawback which the user will need to
> print a lot of pages (~20pages) which are too many and
> it's hard to ensure each printed page is correctly printed in which
> they all can be joint together after printing.
> For this way, i use the idea in
> http://support.microsoft.com/kb/q161299/
> i use
>
> 'Me is the captured PictureBox' area.
> Set Picture1.Picture = CaptureClient(Me) 'Picture1 is an invisible
> PictureBox for printing.
> PrintPictureToFitPage Printer, Picture1.Picture
> Printer.EndDoc
> Set Picture1.Picture = Nothing
>
> Please help. I'm desperate and really truggling.


From: albertleng on
Hi.

I tried to use StretchBlt by testing with 2 pictureboxes as below:

Private Sub Command1_Click()
Dim isOK
Dim wid As Single
Dim hgt As Single

wid = Picture1.ScaleWidth
hgt = Picture1.ScaleHeight

isOK = StretchBlt(Picture2.hdc, 0, 0, wid, hgt, _
Picture1.hdc, 0, 0, wid, hgt, vbSrcCopy)
Picture2.Refresh

Debug.Print isOK
End Sub

Private Sub Form_Load()

With Picture1
Picture2.Width = .Width
Picture2.Height = .Height
End With
End Sub

Yes, whatever seen in Picture1 is copied into Picture2 as it is.
Picture1 has a larger width than the form containing it and also the
screen. If i dont maximise the form, not the whole content of Picture1
is copied into Picture2. It will be the part of the Picture1 being
seen and whatever beside Picture1 (can be other program, desktop or
whatever during that time) that are copied.
How can i make those unseen part of Picture1 being copied to Picture1
as well? Basically, whatever inside Picture1(whether it's seen or not
seen) is copied into Picture2. Any idea?




On Feb 6, 3:06 pm, "Eduardo" <m...(a)mm.com> wrote:
> My idea is to use Printer.PaintPicture to copy each section of the
> picturebox separately.
>
> Printer.PaintPicture Picture1.Image, x, y, width, height
>
> where x, y, width and height define the part to be printed in that page.
>
> Then:
>
> Printer.NewPage
>
> and do the same for others parts of the pic.
>
> And don't forget:
>
> Printer.EndDoc
>
> I think this should work.
>
> "albertleng" <albertl...(a)gmail.com> escribió en el mensajenews:d78d0b92-55a0-45f5-8d73-b42e548f349d(a)x6g2000pre.googlegroups.com...
>
> > My project needs to print a large PictureBox which during runtime only
> > part of it is shown (as it's too large,
> > width=4000 pixels and height= 2000 pixels) and to see the rest of the
> > picturebox, user needs to scroll through
> > the vertical and horizontal bars. On top of the picturebox, there are
> > many controls which are loaded and positioned
> > by user on run-time. Those include lines, labels, another picturebox
> > with image and user-defined controls.
>
> > Now, i need to write a print function which will print that picturebox
> > to not too many pages in A4 size or A3 size.
> > Not too many means less than 5 for both paper size.
> > My questions:
>
> > 1) How can i print the whole picturebox with all its contents and go
> > to next printing page until the whole PictureBox is
> > printed? I tried using the following code but
> > (i)The image of picturebox inside that picture box and user-defined
> > control are not printed whereas others
> >    are printed. Why is that so? How can i print the picturebox
> > including both the "un-printed"?
> >        (ii) Even i can print out the picturebox, only the part where
> > the picturebox is shown is printed. How can i print
> >      the whole picturebox including those parts which needs scrolling
> > to reach?
>
> >       Private Sub CmdPrint_Click()
> >       Dim rv As Long
>
> >       'Picture1 is the picturebox to be printed.
> >       Picture1.SetFocus  ' So that the button doesn't look pressed
> >       Picture2.AutoRedraw = True
>
> >       Picture2.Height = Picture1.Height
> >       Picture2.Width = Picture1.Width
> >       rv = SendMessage(Picture1.hwnd, WM_PAINT, Picture2.hDC, 0)
> >       rv = SendMessage(Picture1.hwnd, WM_PRINT, Picture2.hDC, _
> >          PRF_CHILDREN + PRF_CLIENT + PRF_OWNED)
> >          Picture2.Height = Picture1.Height
> >         Picture2.Width = Picture1.Width
>
> >       Picture2.Picture = Picture2.Image
> >       Picture2.AutoRedraw = False
> >       Printer.Orientation = vbPRORLandscape   ' 2
> >       Printer.Print ""
> >       Printer.PaintPicture Picture2.Picture, 0, 0
> >       Printer.CurrentY = Picture2.Height + 200   ' get below image
> >       Printer.Print "Text1 on the same page as the image!"
> >       Printer.EndDoc
>
> >       CmdPrint.SetFocus  ' Return Focus
> >       End Sub
>
> > 2) I also tried using the Print Screen method which during printing,
> > the scrollbar will move and my program calls
> >   the printscreen and print the picturebox's area which is exposed.
> > The scrollbar will move again and the same process
> >   repeats itself. This has a drawback which the user will need to
> > print a lot of pages (~20pages) which are too many and
> >   it's hard to ensure each printed page is correctly printed in which
> > they all can be joint together after printing.
> >   For this way, i use the idea in
> >http://support.microsoft.com/kb/q161299/
> >   i use
>
> > 'Me is the captured PictureBox' area.
> > Set Picture1.Picture = CaptureClient(Me) 'Picture1 is an invisible
> > PictureBox for printing.
> >        PrintPictureToFitPage Printer, Picture1.Picture
> >        Printer.EndDoc
> >        Set Picture1.Picture = Nothing
>
> > Please help. I'm desperate and really truggling.