Visual Basic User's Guide > Printing
Sending a file to the printer in most cases only requires a single line of code. Text Control's PrintDoc Method will automatically detect the default printer and its settings, so that you only need to specify the range of pages and number of copies you wish to have printed:
[Visual Basic 6] TXTextControl1.PrintDoc "My Print Job", 1, _ TXTextControl1.CurrentPages, 1
The code above will print one copy of the current document. The first parameter, "My Print Job", specifies an arbitrary name under which the print job is displayed in the print manager. The second and 3rd parameters specify the range of pages to be printed, and the last one is number of copies to be printed.
A Common Dialog box can be used to let the user select printer, range of pages, number of copies.
[Visual Basic 6] ' Display a common print dialog CmDialog1.Copies = 1 CmDialog1.FromPage = 1 CmDialog1.ToPage = TXTextControl1.CurrentPages CmDialog1.Min = 1 CmDialog1.Max = CmDialog1.ToPage CmDialog1.Flags = cdlPDHidePrintToFile Or cdlPDNoSelection CmDialog1.ShowPrinter ' Print selected pages TXTextControl1.PrintDoc Form.Caption, CmDialog1.From, _ CmDialog1.ToPage, CmDialog1.Copies
This code is used, for instance, in the MDIDemo sample program.