' A functional program to provide print preview and actual printing facilities for RichText
' documents in a text editor. Written in VB, the program includes functions such as preview
' Zoom-in and Zoom-out, page margins setup, selection of any specific page to preview and
' selection of any range of pages to print. It even allows you to selectively print a
' highlighted text and/or picture only, etc.
' Though there are a few print preview programs around, I have not come across any which is
' geared for RTB in VB context (If a programmer has to arbitrarily apply his/her own fonts,
' the resultant printouts would never be able to reflect the document's original settings).
' Despite VB does not have something like MFC, and despite the many constraints of RTB, we
' we will see that we are able to add functions for a print preview &/or for printing
' page(s) selectively. This RTPreview shows how.
' The Source code is written in native VB. Forms and controls involved are: (1) MDI
' called frmRTFrame. A child form, called RTDoc, which contains a RTB (a hidden RTB and
' a hidden picturebox for use in printing highlighted text/picture only). It is from this
' child form that the RTPreview is invoked . (2) a form for preview, with MDIChild property
' set to False. This RTPreview contains a "home-made" viewport which consists of several
' pictureboxes. Controls placed outside the viewport are a horizontal scrollbar and a
' vertical scrollbar. On top of the viewport are buttons and comboboxes: a "Zoom-in"
' button, a "Zoom-out" button, a combobox for preview sizes, another for list of available
' pages, a "Previous page" button, a "Next page" button, a "Print" button and a "Close"
' button. (3) a form for the page setup (margins).
' Explanation of some key points:
' 1. In a RTB, a single line may have text formatted with different fonts, and there
' may be graphics in between as well. To capture the original contents and settings,
' we first "selprint" the selected page to a hidden picturebox (Since RTB does not
' have a hDC, we cannot "bitblt", nor paintpicture"). We then "stretchblt" that
' picturebox to other pictureboxes according to the desired sizes of preview.
' 2. Since Selprint method does not allow a programmer to set the position of output on
' the printer, and that and comboborinter, anh is
' ne may have text formatted with different fonts,t and comboborinter, anh is
' ne may have text formatted with different fonts,t and comboborinter, anh is
' ne may have text formatted with different fonts,t and comboborinter, anh is0Sincehe py5prmattedka text ehas 2Nmview &/or for printing
' page(s) selective5G:eral
' pictureboxes. Controls placed outside thBside thBsideplarent foontrols pthBsideplarent foof ouoa may be graphallow a programmer to set the position of outpumphahlighted text and/or picture only, etc.
ic =ext asr for printing
' page(s) selectively. Tanting
'inting
' page(s) selectively.sr for praa.20t a5p(s) selective5G:erTrld14dv we A1a "eion of output on