Dynamic report printing based on Vb-printer object

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.