0 Introduction
In the author's "Student Status management System", there is a data query module, whose task is to query and browse the set conditions of students or class data, in which the "Print" button function is to display the contents of the table printed out. Because the table and the field in the query results are not fixed, make use of VB itself with the database report is difficult to achieve dynamic printing, the author after the MSHFlexGrid control, printer object More in-depth study, research, follow Windows "WYSIWYG" thought, The organic combination of the two programs, the realization of both the query data can be displayed, according to the content of the MSHFlexGrid control of the actual size of the fast output, the overall effect is good.
1 Introduction to control and printing technology
1. 1 MSHFlexGrid Control
The Microsoft Hierarchical FlexGrid (MSHFlexGrid) control provides an Excel spreadsheet-like feature that controls the ability to display and manipulate data in a table, and when sorting, merging, and formatting tables that contain strings and pictures. has a strong flexibility.
The Cols and rows properties in the MSHFlexGrid control determine the number of columns and rows in the MSHFlexGrid control, and the row and Col properties specify the current cell, using the mouse or the arrow keys to change the position of the cell, Textmatrix (i, J) property is the text content that shows the position of the J column in the grid, which can be read and write, and the column width and row height of the cell in the table are set by the Colwidth and RowHeight properties respectively. The MSHFlexGrid control can be used mouse to drag to achieve row height, column width adjustment, or through the writing process to the table row height and column width of the unified set.
1. 2 Printing technology
VB provides three techniques for printing text and graphics:
① create the desired output in the form, and then call the PrintForm method to print the form.
② first set the default printer in the Printers collection, and then transfer the body and graphics to the printer.
③ first transmits the text and graphics to the printer object, then prints the output.
Because the printer object is a device-independent picture space, it supports the use of print, PSet, line, PaintPicture, and Circle methods to create text and graphics, and to best match the text and graphics to the printer's resolution and functionality. So for different types of printers, the printer object provides the best print quality.
Printer Object printing output, the main need to set the CurrentX and CurrentY properties, these two properties determine the Printer object in the current page of the output location, if the content of the printed document is more, the NewPage method for page-changing, Finally, use the EndDoc method to finish printing the document.