TPreview
Source: source/classes/rpreview.prg
Standalone class (not inherited from TControl)
TPreview is the print preview window engine for FiveWin. It is automatically invoked when using
the PREVIEW clause with the PRINTER command, and provides a full-featured
preview environment with zoom, page navigation, two-page view, printing, and export capabilities.
It is also used internally by TReport for report preview.
Key DATA Members
| DATA | Type | Description |
|---|---|---|
oDevice | TPrinter | The printer device object being previewed |
oReport | TReport | Optional TReport object bound to this preview |
oWnd | TWindow | The preview window |
oBar | TReBar | Toolbar with navigation and action buttons |
nPage | Numeric | Current page number (1-based) |
nZFactor | Numeric | Zoom factor multiplier |
lTwoPages | Logical | Two-page side-by-side view mode |
lZoom | Logical | Zoom mode active when resizing window |
aFactor | Array | Array of available zoom factor values |
oMeta1 | TMetafile | Current page metafile for rendering |
oMeta2 | TMetafile | Second page metafile (two-page mode) |
oLvw | TListView | Page thumbnail list view (mini pages) |
Class DATA
| CLASSDATA | Description |
|---|---|
bPrint | Code block executed on Print action |
bExportToWord | Code block for Word export |
bEmail | Code block for Send Email action |
bSaveAsPDF | Default: saves as PDF |
bSaveAsWord | Default: saves as DOC |
Methods
| Method | Description |
|---|---|
New( oDevice, oReport ) | Create preview for a printer device and optional report |
Activate() | Show the preview window maximized |
BuildWindow() | Construct the preview window and toolbar |
BuildButtonBar() | Build the rebar toolbar with navigation buttons |
BuildMenu() | Build the zoom and two-page popup menus |
GoPage( nPage ) | Go to a specific page number |
NextPage() | Move to the next page |
PrevPage() | Move to the previous page |
TopPage() | Move to the first page |
BottomPage() | Move to the last page |
Zoom( lMenu ) | Toggle zoom mode or select zoom level from menu |
TwoPages( lMenu ) | Toggle two-page view or select from menu |
PrintPage() | Print the current page |
SetFactor( nValue ) | Set zoom factor directly |
SaveAs( lPDF, cFile, lView ) | Save as PDF (.T.) or DOC (.F.) |
SaveAsMenu() | Show Save As type selection dialog |
ExportToMSWord() | Export current document to Microsoft Word |
ExportToMSExcel() | Export current report data to Excel (requires report with bInit/bToExcel) |
SendEmail() | Send the document as an email attachment |
SelPrinter( cPrinter ) | Change output printer from within preview |
PaintMeta() | Repaint the current page metafile |
VScroll( nType, lPage, nSteps ) | Vertical scrolling |
HScroll( nType, lPage, nSteps ) | Horizontal scrolling |
CheckStyle() | Apply dark mode styling when Windows dark theme is active |
Example: Print Preview with PRINTER Command
#include "FiveWin.ch"
function Main()
local oWnd
DEFINE WINDOW oWnd TITLE "Print Preview Demo" SIZE 600, 400
@ 20, 20 BUTTON "&Print Preview" SIZE 120, 30 OF oWnd ;
ACTION DoPreview()
ACTIVATE WINDOW oWnd CENTERED
return nil
function DoPreview()
PRINTER oPrn PREVIEW
PAGE
@ 10, 10 SAY "Hello from FiveWin!" FONT oPrn:oFont
@ 30, 10 SAY "Page: " + Str( oPrn:nPageCount )
ENDPAGE
PAGE
@ 10, 10 SAY "This is page 2"
ENDPAGE
ENDPRINTER
return nil
Notes
- TPreview is used automatically when
PRINTER ... PREVIEWis specified. It can also be instantiated directly by passing aTPrinterdevice and optionalTReportobject. - The preview window supports keyboard navigation: arrow keys for scrolling, Page Up/Down for page navigation, and +/- for zoom in/out.
- Dark mode is automatically detected and applied on Windows 11 when the system theme is set to dark.
- Export capabilities (PDF, Word, Excel) depend on the printer device and report having the appropriate code blocks assigned.
- The
oLvw(list view thumbnails) provides a visual page selector sidebar. It can be hidden vialListViewHideclass data.