Prev: Progressbar in Listview v5 ?
Next: Is there a way of fetching the date/time or size of a file on the Internet?
From: Webbiz on 6 Nov 2009 16:04 Now that the printer is selected, I'm trying to print the form. Here is my routine called "PrintTheForm" in a module called modPrinting. Public Sub PrintTheForm(ByVal frm As Form) Dim hWndForm As Long Dim hDCForm As Long Dim LeftForm As Long Dim TopForm As Long Dim WidthForm As Long Dim HeightForm As Long 'define the screen coordinates (upper 'corner (0,0) and lower corner (Width, Height) LeftForm = 0 TopForm = 0 WidthForm = frm.ScaleX(frm.Width, vbTwips, vbPixels) HeightForm = frm.ScaleY(frm.Height, vbTwips, vbPixels) 'copy the form to the picture box Call BitBlt(frmMain.Picture1.hDC, 0, 0, WidthForm, HeightForm, _ frm.hDC, LeftForm, TopForm, vbSrcCopy) Printer.PaintPicture frmMain.Picture1, 0, 0 End Sub I have included a hidden Picture1 (picbox) on my main form for use with the BitBlt routine. It is contained in frmMain. When the code gets to Printer.PaintPicture frmMain.Picture1, I get an "Invalid Picture" error. What this is suggesting to me is that there isn't anything copied into Picture1. Still searching. Webbiz
From: Eduardo on 6 Nov 2009 16:06 Webbiz escribi�: > On Fri, 06 Nov 2009 15:19:58 -0300, Eduardo <mm(a)mm.com> wrote: > >> In VB you can change the printer like this: >> >> Dim prn As Printer >> Dim iDesiredPrinterName As String >> Dim iFound As Boolean >> >> iDesiredPrinterName = "Printer Name" >> >> For Each prn In Printers >> If prn.DeviceName = iDesiredPrinterName Then >> Set Printer = prn >> iFound = True >> End If >> Next prn >> If Not iFound Then >> MsgBox "Printer '" & iDesiredPrinterName & _ >> "' not found", vbInformation >> End If >> >> This does not affect Windows's default printer. >> >> >> > > Using the above, I'm assuming that all the printer names will need to > be pulled from (registry?) (win.ini?) and displayed in a list so that > the user can select it. Once selected, it would then be applied to the > variable "iDesiredPrinterName". You don't need the registry or APIs. If you look to the routine, you can see that the prn variable refers to a printer, and it has all the properties, and one of the properties is DeviceName. There you have the printer name. for each prn in Printers lstPrinters.AddItem prn.DeviceName Next prn
From: Webbiz on 6 Nov 2009 16:10 On Fri, 6 Nov 2009 15:51:53 -0500, "Nobody" <nobody(a)nobody.com> wrote: >See this page: > >Print picture to fit the page: >http://www.freevbcode.com/ShowCode.asp?ID=194 > Thanks, this should be useful. Now I can do without having the user decide on whether to "Shrink" or go "Landscape", as this routine apparently makes that decision for them. Nice. :-) Webbiz
From: Webbiz on 6 Nov 2009 16:24 On Fri, 06 Nov 2009 18:06:41 -0300, Eduardo <mm(a)mm.com> wrote: >Webbiz escribi�: >> On Fri, 06 Nov 2009 15:19:58 -0300, Eduardo <mm(a)mm.com> wrote: >> >>> In VB you can change the printer like this: >>> >>> Dim prn As Printer >>> Dim iDesiredPrinterName As String >>> Dim iFound As Boolean >>> >>> iDesiredPrinterName = "Printer Name" >>> >>> For Each prn In Printers >>> If prn.DeviceName = iDesiredPrinterName Then >>> Set Printer = prn >>> iFound = True >>> End If >>> Next prn >>> If Not iFound Then >>> MsgBox "Printer '" & iDesiredPrinterName & _ >>> "' not found", vbInformation >>> End If >>> >>> This does not affect Windows's default printer. >>> >>> >>> >> >> Using the above, I'm assuming that all the printer names will need to >> be pulled from (registry?) (win.ini?) and displayed in a list so that >> the user can select it. Once selected, it would then be applied to the >> variable "iDesiredPrinterName". > >You don't need the registry or APIs. If you look to the routine, you can >see that the prn variable refers to a printer, and it has all the >properties, and one of the properties is DeviceName. There you have the >printer name. > >for each prn in Printers > lstPrinters.AddItem prn.DeviceName >Next prn What I was trying to say is that the routine above appears to rely on you already knowing the name of the printer and hard coding it. I assume this because of the line: iDesiredPrinterName = "Printer Name" Which I assume is to be the actual name of one of the printers in place of "Printer Name". Since I don't know the names of the printers that my users will have, that's why I said I would have to get the names 'before' the above code could be used. I understand (now) that I can do a loop on Prn in Printers and grab each .DeviceName to add to a list for selection, THEN run the above code to apply the selection. Or do I need to take it easy on the Rum? Thanks. :-) Webbiz
From: Nobody on 6 Nov 2009 16:52
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 |