|
Printing |
Top Previous Next |
|
Printing and Print Preview
Now you can print a MLG worksheet to the printer and preview it beforehand. The printing functionality is contained in a DLL named MLG_Print.DLL that when present in the MLG.DLL directory, will allow faithful printing of a sheet allowing for optional row and column header display, repeat rows and columns and much more. The MLG_Print.DLL is an extension of Gary Beene's fine gbPrintPreview project. Many thanks to Gary. Below is a screen shot of the print preview dialog which will allow for a lot of customization while viewing to put the finishing touches on your output.
The basic strategy to printing is once the is worksheet built, define a Print Area with the mouse or in code, define Page parameters with the standard Page Setup dialog or in code, define Print parameters with the standard Print dialog or in code, define other printing options such as displaying grid lines or displaying row/column headers etc, and then print the job directly or send it to the Print Preview for viewing and/or tweaking before sending it to the printer. When a sheet is sent to be printed, a print file is made and the MLG_Print.DLL will reference that file. It is possible to save a file for later printing.
MLG supports the display of up to 4 repeating rows at the top of the printarea on a given page and up to 4 repeat columns to the left of the printarea for a given printed page. This attempts to mirror some of Excel's print capability. As a note, merged cells are not supported at this time in repeat rows and columns. Also, MLG supports the printing of row headers and column headers. Though possible to display both repeat rows / columns and headers at the same time, the result is not attractive.
The registered version of MLG can print up to 999 pages at one time. The freeware version of MLG has Print Area restriction of 10 columns by 50 rows maximum size.
Default Setting
Here is a listing of default setting that if the minimum calls are made such as SendMessage hGrid,%MLG_SETPRINTAREA,VARPTR(MyPrintAreaRect),0 SendMessage hGrid,%MLG_PRINT,0,0 'Show no Print Dialog and regenerate the print file
Margin Units inches Margins Top,Left,Bottom,Right all 0.25 inches (as a note, all margins are stored internally as thousandths of inches) Print Area Top,Left,Bottom,Right all 0 (will not print - an area must be set) RECT elements are cells Repeat Rows Top,Bottom all 0 (RECT elements are cells) Repeat Cols Left,Right as 0 (RECT elements are cells) AutoClose Set to autoclose Num Copies 1 Print Range All Printer Default Printer Orientation Portrait Paper Letter Tray Auto Page Order Right then Down Vert Center Off Horz Center Off Gridlines On Row Header Off Col Header Off Page Header None Page Footer None
Altering Settings before print file made by code Wrapper functions in the MLG.inc file can be used in view of messages to set most printing parameters.
MLG_SetPrintOptions(mygrid AS LONG, ShowRowColHeaders AS LONG, PrintPageOrder AS LONG, PrintJustification AS LONG,SuppressGridLines AS LONG)
MLG_SetPrintDlg(mygrid AS LONG, NumCopies AS LONG, AutoClose AS LONG, PageFrom AS LONG,PageTo AS LONG)
MLG_SetPageSetupDlg(mygrid AS LONG, MyPaper AS LONG, MyTray AS LONG, MyOrientation AS LONG,MMFlag AS LONG)
Setting a Print Area A print area must be defined before a worksheet can be printed. There are multiple ways to do this. 1) In code - Use the MLG_SETPRINTAREA message such as: PrintAreaRect.nTop=1 PrintAreaRect.nLeft=1 PrintAreaRect.nBottom=15 PrintAreaRect.nRight=6 SendMessage hGrid1, %MLG_SETPRINTAREA,VARPTR(PrintAreaRect),0
2) Let the user do it. Assuming that the b switch was used in creating the grid, then the user can select a block of cells. If the programmer has the %MLG_SETPRINTAREA message a available in, say a menu option, with both the wParam and lParam defined as zero then print area will be set to the selection of cell - much in the spirit of Excel. The programmer can also disable the user ability to set a printer area by the call:
SendMessage hGrid1, %MLG_ALTERATTRIBUTE, %MLG_SUPPRESSUSERSETPRINTAREA,1
Setting Repeating Rows and Columns The user can set repeating rows and columns (up to 4 each) much like Excel. There are multiple ways to do this. 1) In code - Use the MLG_SETPRINTAREA message such as: RepeatRect.nTop=1 RepeatRect.nLeft=2 RepeatRect.nBottom=1 RepeatRect.nRight=3 SendMessage hGrid1, %MLG_SETPRINTAREA,0,VARPTR(RepeatRect)
which sets row 1 as the top repeating row at the top of each page and sets columns 2 and 3 as repreating columns to the left of each page.
2) Let the user do it. Assuming that the b3 switch was used in creating the grid, then the user can select an entire block of cells in the headers. If the programmer has the %MLG_SETPRINTAREA message a available in, say a menu option, with both the wParam and lParam defined as zero and the user HOLDS DOWN THE SHIFT KEY then the repeating rows or columns will be set . The programmer can also disable the user ability to set repeating rows and columns by the call:
SendMessage hGrid1, %MLG_ALTERATTRIBUTE, %MLG_SUPPRESSUSERSETPRINTAREA,1
If the user holds down both the shift key and the control key while setting an entire block of rows or columns then the repeat group will be turned off.
This process may be a little convoluted for the user and the programmer may want to set up his own dialog to let the user handle this process.
NOTE: Merged cells are not supported at this time in repeat rows and columns.
Displaying Grid Headers For data table type grids it may be desirable to show the grid headers.
1) You can use the built in wrapper
MLG_SetPrintOptions(Grid1, %MLG_PRINT_SHOWCOLHEADERS, %MLG_PRINT_DOWNTHENACROSS,%MLG_PRINTNOCENTERING, %MLG_PRINT_SHOWGRIDLINES) which will show the column headers only
or 2) the use the message %MLG_SETPRINTMARGINS directly.
Note: Though it is possible to display grid headers and repeat rows and/or columns together, the result is not visually appealling.
Print Preview Toolbar
Assuming that the MLG_Print.dll is present and a print area as been defined, then the print preview dialog can be display with the message:
SendMessage hGrid1, %MLG_PRINTPREVIEW, 0,0
The wParam equal zero means do not show the standard window print dialog and the lParam equal zero means to generate an new print file to be used by the MLG_Print.dll. If the lParam was non zero then the MLG_Print.dll would not generate a new print file and the existing one would be used. This allows saving these print file to be save and displaying them at a latter time.
1) About Displays info about the MLG_Print.DLL
2) Altering Settings in Print Preview
This will bring up the above dialog box where print parameters can be changed. If the Change Printer button is pushed then the standard Print Dialog will be brought up so a different printer can be selected. Paper and Tray dropdown combobox will be enabled so paper and tray selections can be made. Pushing the APPLY button will make changes and not dismiss the dialog, OK will dismiss the dialog box a keep the changes, CANCEL will restore the previous settings.
3) Go To the First Page
4) Go To the Previous Page
5) Current Page
The current page is displayed in the label and in the Dialog caption.
6) Go To the Next Page
7) Go To the Last Page
The last page will be displayed in the Dialog caption. For example, if there are 7 pages, the caption may read Page 3 of 7 Page(s).
8) Print the Displayed Range
Pushing this button will send the file to the printer using all the setting that are active. The pages that will print are displayed in the adjacent 2 textboxes which describe the range to be printed
9) Print From this Page
First page to be printed
10) Print To this Page
Last page to be printed
11) Zoom
Set the print preview zoom
12) Portrait Orientation Toggle
Toggle between portrait and lanscape of the currently selected paper size
13) Show Header Toggle
Toggle between showing or hiding the currently defined header
14) Show Footer Toggle
Toggle between showing or hiding the currently defined footer
15) Show Margins Toggle
Toggle between showing or hiding the margin in the print preview window. The margin lines will never be printed.
16) Exit
Close the print preview dialog
|