Printing ALL content in large PictureBox which has scrollbars
Author |
Message |
albertlen #1 / 6
|
 Printing ALL content in large PictureBox which has scrollbars
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://www.*-*-*.com/ 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.
|
Tue, 26 Jul 2011 02:46:50 GMT |
|
 |
Bill McCarth #2 / 6
|
 Printing ALL content in large PictureBox which has scrollbars
Hi albert, Sounds like you want to create another bitmap and copy to that using StretchBlt.
Quote: > 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.
|
Tue, 26 Jul 2011 13:16:51 GMT |
|
 |
Eduard #3 / 6
|
 Printing ALL content in large PictureBox which has scrollbars
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.
Quote: > 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.
|
Tue, 26 Jul 2011 15:06:43 GMT |
|
 |
albertlen #4 / 6
|
 Printing ALL content in large PictureBox which has scrollbars
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?
Quote: > 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.
> > 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.
|
Fri, 29 Jul 2011 14:02:00 GMT |
|
 |
albertlen #5 / 6
|
 Printing ALL content in large PictureBox which has scrollbars
Dear all, any reply to my latest post? Dear Eduardo, i tried what you wrote before. The other controls i added on the picturebox either during run-time or design-time just won't be printed. Thanks.
Quote: > 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?
> > 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.
> > > 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.
|
Sun, 31 Jul 2011 10:40:08 GMT |
|
 |
Eduard #6 / 6
|
 Printing ALL content in large PictureBox which has scrollbars
I really didn't read it well the first time. I thought it was an image, not controls. Sorry. For your actual case, I think you have to do the proper scrolling by code of each picturebox section before copying it. What you are going to copy _must_ be visible on the screen.
Dear all, any reply to my latest post? Dear Eduardo, i tried what you wrote before. The other controls i added on the picturebox either during run-time or design-time just won't be printed. Thanks.
Quote: > 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?
> > 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.
> > > 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.
|
Sun, 31 Jul 2011 20:26:24 GMT |
|
|
|