Prev: Progressbar in Listview v5 ?
Next: Is there a way of fetching the date/time or size of a file on the Internet?
From: Eduardo on 6 Nov 2009 17:51 Webbiz escribi�: > On Fri, 06 Nov 2009 18:06:41 -0300, Eduardo <mm(a)mm.com> wrote: For printing the whole form, you can use this: (add a picturebox and a command button) (notice: the non client area of the form -title bar and borders- won't print properly unless it is fully displayed on the screen) 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 Private Sub PrintForm1() Dim WidthForm As Long Dim HeightForm As Long WidthForm = Me.ScaleX(Me.Width, Me.ScaleMode, vbPixels) HeightForm = Me.ScaleY(Me.Height, Me.ScaleMode, vbPixels) Picture1.Visible = False Picture1.AutoRedraw = True Picture1.Move 0, 0, ScaleX(Me.Width, vbTwips, Me.ScaleMode), _ ScaleY(Me.Height, vbTwips, Me.ScaleMode) Call BitBlt(Picture1.hDC, 0, 0, WidthForm, HeightForm, _ GetWindowDC(Me.hwnd), 0, 0, vbSrcCopy) Printer.PaintPicture Picture1.Image, 0, 0 Printer.EndDoc End Sub Private Sub Command1_Click() PrintForm1 End Sub
From: Eduardo on 6 Nov 2009 18:33 Webbiz escribi�: > When the code gets to Printer.PaintPicture frmMain.Picture1, I get an > "Invalid Picture" error. frmMain.Picture1.Image
From: Webbiz on 6 Nov 2009 20:56 On Fri, 06 Nov 2009 19:51:36 -0300, Eduardo <mm(a)mm.com> wrote: >Webbiz escribi�: >> On Fri, 06 Nov 2009 18:06:41 -0300, Eduardo <mm(a)mm.com> wrote: > >For printing the whole form, you can use this: >(add a picturebox and a command button) >(notice: the non client area of the form -title bar and borders- won't >print properly unless it is fully displayed on the screen) > >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 > >Private Sub PrintForm1() > Dim WidthForm As Long > Dim HeightForm As Long > > WidthForm = Me.ScaleX(Me.Width, Me.ScaleMode, vbPixels) > HeightForm = Me.ScaleY(Me.Height, Me.ScaleMode, vbPixels) > > Picture1.Visible = False > Picture1.AutoRedraw = True > Picture1.Move 0, 0, ScaleX(Me.Width, vbTwips, Me.ScaleMode), _ > ScaleY(Me.Height, vbTwips, Me.ScaleMode) > > Call BitBlt(Picture1.hDC, 0, 0, WidthForm, HeightForm, _ > GetWindowDC(Me.hwnd), 0, 0, vbSrcCopy) > Printer.PaintPicture Picture1.Image, 0, 0 > Printer.EndDoc >End Sub > >Private Sub Command1_Click() > PrintForm1 >End Sub 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? Thanks. Webbiz
From: Webbiz on 6 Nov 2009 21:01 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 Error: Object does not support this property.
From: Webbiz on 6 Nov 2009 21:03
On Fri, 6 Nov 2009 16:52:04 -0500, "Nobody" <nobody(a)nobody.com> wrote: >You don't have to make your own form if you use the common dialogs. See >PrintDlg/PrintDlgEx in MSDN if you want to show the common Print dialog >without having to use the common dialog control OCX. Search the web for "vb >PrintDlg" for samples. > >Another option is to use the DLL in this article. It provides more print >features than the common dialog control, including returning the printer >name that the user has selected, however, this DLL require registration. > >HOW TO: Raise and Control Print Dialog Boxes from Visual Basic >http://support.microsoft.com/kb/322710 > The problem of setting the printer has been solved. I like the simple listbox and control button solution rather than having to deal with the whole common dialog control. But right now, I just can't print the form to the printer in its entirety. :-0 Webbiz |