|
yaro248 (m)
|
hi, can anyone help me with the code to print with vb6? I am writing a program to print some text but have no idea on how to do that. I can load my printers anyway using my Common Dialogue Control.
|
|
|
|
|
|
Fdeveloper (m)
|
Unfortunetaly, printing is somewhat cumbersome with VB6 but I hope he following sample gives you an idea of how to go about it
Private Sub cmdPrint_Click()
On Error GoTo PrintClickError 'Prompt the user to select a printer Printer.EndDoc Printer.TrackDefault = True frmMDIAdmin!dlgMDI.PrinterDefault = True ' Note the Dialog control referenced here is in a seperate MDI form frmMDIAdmin!dlgMDI.Flags = cdlPDNoPageNums Or cdlPDNoSelection frmMDIAdmin!dlgMDI.CancelError = True frmMDIAdmin!dlgMDI.ShowPrinter Printer.Font = "Arial" Printer.FontBold = True Printer.FontSize = 16 Printer.FontItalic = False
Printer.CurrentX = (2 + (96 - Printer.TextWidth("This is the title of the page"))) / 2 Printer.Print "This is the title of the page" Printer.Print 'Column Headings Printer.FontSize = 11 Printer.FontBold = True Printer.CurrentX = 2 Printer.Print "First";
Printer.CurrentX = 35 Printer.Print "Second"; Printer.CurrentX = 45 Printer.Print "Third"; Printer.CurrentX = 55 Printer.Print "Fourth" Printer.FontItalic = False Printer.FontSize = 10 Printer.FontBold = False Printer.EndDoc DoEvents
Exit Sub PrintClickError:
Exit Sub End Sub
|
|
|
|
|
|
yaro248 (m)
|
Thanks FDeveloper, I'm grateful. But what does CurrentX for the Printer Object mean?
|
|
|
|
|
|
Fdeveloper (m)
|
The printer properties .CurrentX and .CurrentY are used to set the current print position on a page where .CurrentX refers to a column and CurrentY refers to a row. Imagine that you are printing on a page that has 50 lines and each line can contain 80 characters, since you most likely don't intend to print every character on every line, you use .CurrentY to set the row (i.e. Line) that you want to print on and .CurrentX to set the column. So in my example, you can see where I increase the .CurrentX value to print column headings.
|
|
|
|
|
|
yaro248 (m)
|
yaeh, thanks. been really helpful. I also used the Printer Object.
|
|
|
|
|
|