Print form with Printer object

zhaozj2021-02-11  214

Print form with Printer object

With the MSFlexGrid control, you want to print it out, the easiest way is to use the PrintForm method, however this is only suitable for the data that can be displayed by the screen, that is, the amount of data is small, and this printing effect is very poor. With the Printer object, print programming, although it is trouble, but the effect is quite good, you can customize the print format, the print pages, the thickness of the table, the font size, etc. In fact, print programming is made in Printer objects.

Below I will use an example:

The content of print is a data sheet, which is only two column data, including title, subtitle. (Printing with A4)

Suppose the data at c_dataaarray (), and R_DataArray (), the field name of the two data items, respectively, respectively.

Public Sub PRINTTABLE () 'Initialization

Dim Printer1 as Printer

DIM Pageheaderdim PageFootdim Pageleftdim Pagertem USEWIDTHDIM USEHEHEHTDIM I, J, K AS INTEGERDIM WORD AS STRINGDIM StartXDim Startydim Startyline 'The starting point for record print vertical line

DIM Endyline 'is used to record the last point of print vertical line

Set page parameters

PageHeader = 25PageLeft = 20PAgeright = 20

With printer1 .PaperSize = 9 .ScaleMode = 6 .FontBold = True .ScaleLeft = -20 .ScaleTop = -25 .ScaleWidth = 210 'to A4 paper .ScaleHeight = 297 usewidth = .ScaleWidth - 40 useheight = .ScaleHeight - 50. CurrentX = 0 .CurrentY = 0 .DrawWidth = 5End With 'print titles With printer1 .FontSize = 20 .CurrentX = (usewidth - .TextWidth (DataTitle)) / 2 .CurrentY = pageheader .ScaleTopEnd With printer1.Print DataTitle' Print subtitle Printer1.fontsize = 15 Word = DataTitle2 Printer1.currentx = usewidth - Printer1.textwidth (Word) Printer1.print Word 'Printing the first line LINE method can not be used in with .... End with

Printer1.currentx = PageLeft Printer1.scaleleftStartyline = Printer1.currenty 'line width

printer1.Line - ((printer1.ScaleLeft printer1.ScaleWidth - pageleft), printer1.CurrentY) printer1.FontSize = 10'printer1.Print vbLfprinter1.CurrentY = printer1.CurrentY 1 'to print the first field name starty = printer1. Currentyprinter1.currentx = (Printer1.scalewidth - 40) / 2 - printer1.textwidth (c_name) / 2printer1.print c_name

"Print the second field name printer1.CurrentX = usewidth / 2 ((usewidth / 2 - printer1.TextWidth (R_Name)) / 2) printer1.CurrentY = startyprinter1.Print R_Nameprinter1.CurrentY = printer1.CurrentY 1

'Print data and horizontal line, ROWNUM is the number of data lines

For i = 1 to rownum 'judgment whether the page has been filled with IFprinter1.currenty> = useHeight Then

'Horizontal print printer1.CurrentX = printer1.ScaleLeft pageleft printer1.Line - ((printer1.ScaleLeft printer1.ScaleWidth - pageleft), printer1.CurrentY) printer1.CurrentY = printer1.CurrentY 1' to print three bars endyline = printer1.CurrentY printer1.Line (0, startyline) - (0, endyline) printer1.Line (usewidth / 2, startyline) - (usewidth / 2, endyline) printer1.Line (usewidth, startyline) - (usewidth, endyline) ' Print page number With printer1 .CurrentX = (.ScaleWidth - .TextWidth (.Page)) / 2 - pageleft .CurrentY = useheight 3 End With printer1.Print printer1.Page printer1.NewPage With printer1 .CurrentX = pageleft .ScaleLeft. CurrentY = pageheader .ScaleTop startyline = .CurrentY End With End If 'print line data printer1.CurrentX = ((printer1.ScaleWidth - 40) / 2 - printer1.TextWidth (C_DataArray (i))) / 2 starty = printer1.CurrentY PRINTER1.PRINT C_DataArray (i) printer1.CurrentX = (printer1.ScaleWidth - 40) / 2 ((printer1.ScaleWidth - 40) / 2 - printer1.TextWidth (R_DataArray (i))) / 2 printer1.CurrentY = starty printer1.Print R_DataArray (i) printer1.CurrentY = printer1.CurrentY 1 Next i 'last print a horizontal line printer1.CurrentX = printer1.ScaleLeft pageleft printer1.Line - ((printer1.ScaleLeft printer1.ScaleWidth - pageleft), printer1.CurrentY) Endyline = printer1.currenty '

转载请注明原文地址:https://www.9cbs.com/read-4620.html

New Post(0)