How Do I Do It
And So That The User Can Choose The Printer
Thanx
Lavarock09
Printable View
How Do I Do It
And So That The User Can Choose The Printer
Thanx
Lavarock09
This is the preferred method of choosing a printer.
http://vbforums.com/attachment.php?attachmentid=37738
I use a WYSIWYG form to print a rtb as a preview pane before printing it. Google, and you will get the M$ site that explains it.
i got to this site
http://support.microsoft.com/kb/q146022/
and i have implimented this, but i cant choose the printer
The program that I posted lets you select the printer that will be used until your program ends.
but i want it so that the printer dialog box comes up and you can choose a printer and it will print what is in the richtextbox
Hmmm. Maybe I posted the wrong example. Try this one.
EDIT: Removing duplicate code.
http://vbforums.com/attachment.php?attachmentid=41070
this is the code for my command button for printing
VB Code:
Private Sub Command3_Click() Dim printDlg As PrinterDlg Set printDlg = New PrinterDlg ' Set the starting information for the dialog box based on the current ' printer settings. printDlg.PrinterName = Printer.DeviceName printDlg.DriverName = Printer.DriverName printDlg.Port = Printer.Port ' Set the default PaperBin so that a valid value is returned even ' in the Cancel case. printDlg.PaperBin = Printer.PaperBin ' Set the flags for the PrinterDlg object using the same flags as in the ' common dialog control. The structure starts with VBPrinterConstants. printDlg.Flags = VBPrinterConstants.cdlPDNoSelection _ Or VBPrinterConstants.cdlPDNoPageNums _ Or VBPrinterConstants.cdlPDReturnDC Printer.TrackDefault = False ' When CancelError is set to True the ShowPrinterDlg will return error ' 32755. You can handle the error to know when the Cancel button was ' clicked. Enable this by uncommenting the lines prefixed with "'**". '**printDlg.CancelError = True ' Add error handling for Cancel. '**On Error GoTo Cancel If Not printDlg.ShowPrinter(Me.hWnd) Then Debug.Print "Cancel Selected" Exit Sub End If 'Turn off Error Handling for Cancel. '**On Error GoTo 0 Dim NewPrinterName As String Dim objPrinter As Printer Dim strsetting As String ' Locate the printer that the user selected in the Printers collection. NewPrinterName = UCase$(printDlg.PrinterName) If Printer.DeviceName <> NewPrinterName Then For Each objPrinter In Printers If UCase$(objPrinter.DeviceName) = NewPrinterName Then Set Printer = objPrinter End If Next End If ' Copy user input from the dialog box to the properties of the selected printer. Printer.Copies = printDlg.Copies Printer.Orientation = printDlg.Orientation Printer.ColorMode = printDlg.ColorMode Printer.Duplex = printDlg.Duplex Printer.PaperBin = printDlg.PaperBin Printer.PaperSize = printDlg.PaperSize Printer.PrintQuality = printDlg.PrintQuality ' Display the results in the immediate (Debug) window. ' NOTE: Supported values for PaperBin and Size are printer specific. Some ' common defaults are defined in the Win32 SDK in MSDN and in Visual Basic. ' Print quality is the number of dots per inch. With Printer Debug.Print .DeviceName If .Orientation = 1 Then strsetting = "Portrait. " Else strsetting = "Landscape. " End If Debug.Print "Copies = " & .Copies, "Orientation = " & _ strsetting If .ColorMode = 1 Then strsetting = "Black and White. " Else strsetting = "Color. " End If Debug.Print "ColorMode = " & strsetting If .Duplex = 1 Then strsetting = "None. " ElseIf .Duplex = 2 Then strsetting = "Horizontal/Long Edge. " ElseIf .Duplex = 3 Then strsetting = "Vertical/Short Edge. " Else strsetting = "Unknown. " End If Debug.Print "Duplex = " & strsetting Debug.Print "PaperBin = " & .PaperBin Debug.Print "PaperSize = " & .PaperSize Debug.Print "PrintQuality = " & .PrintQuality If (printDlg.Flags And VBPrinterConstants.cdlPDPrintToFile) = _ VBPrinterConstants.cdlPDPrintToFile Then Debug.Print "Print to File Selected" Else Debug.Print "Print to File Not Selected" End If Debug.Print "hDC = " & printDlg.hdc End With Exit Sub '**Cancel: '**If Err.Number = 32755 Then '** Debug.Print "Cancel Selected" '**Else '** Debug.Print "A nonCancel Error Occured - "; Err.Number '**End If End Sub
how do i make it print the richtextbox's text
It was in the code:
VB Code:
rtb.SelPrint printDlg.hDC
with rtb being the name of my rich text box. I ran it before I posted, and it worked.
i can't see it in the code on here
Sorry, I thought that was the latest. I'll rebuild the zip file.
Hmm. It got smaller, so I don't know what was in it. Then new one has replaced it.
thanx, it works fine apart from 1 thing, how do I put a gap around the side so it doesn't print right to the edge
Try the .RightMargin property or maybe .SelIndent and .SelRightIndent.
i want it all round the richtextbox
Try this
VB Code:
Option Explicit Private Sub Command1_Click() Dim margin As Integer margin = 600 With rtb .SelStart = 1 .SelLength = Len(.Text) .SelIndent = margin .SelRightIndent = margin End With End Sub
so with that, when i print, there will be a space around the page
Yes, the margin is in twips, I think. I just changed them until the text appeared indented properly. I went from 6 to 60 to 600. It depends how wide your rtb is.