Working With printform1
In this section we will create a small program that demonstrates using each of the controls on a printed form. Learning from an actual program is generally the best approach. The following sample creates a print form, populates it with controls and graphics, and then prints it to the print preview window. It does not use any of the data-aware features of the controls, but doing so is trivial, it merely requires also creating and adding the data sources and tables, and then assigning fields and display formats to the controls. That is identical to the way it works in normal data-aware forms, so for the purpose of this demonstration, it will be left out. Here is the sample code:
function main() printform1 pf printform1page page type(printform1graphic) g type(printform1control) c integer e wxwindow w wxbitmap bmp wxfont font string s, url e = 0 w =@ wxwindow.new(1, 1, 300, 200, \ captiontext="Close me when done", error=e) if w !@= .nul w.onvisibilitychange.function =@ quit pf =@ printform1.new(error=e) page =@ pf.addpage(210000, 297000, 0xffffff, name="ptest", \ error=e) g =@ pf.addgraphic(printform1line, point.new(30000, 30000), \ point.new(180000, 30000), width=100, \ rgb=0, printname="l1", page=page, error=e) g =@ pf.addgraphic(printform1rectangle, \ point.new(30000, 50000), \ point.new(100000, 70000), borderwidth=100,\ rgb=0xff00, borderrgb=0x0, printname="r1",\ page=page, error=e) g =@ pf.addgraphic(printform1triangle, \ point.new(110000, 50000), \ point.new(140000, 50000), \ point.new(125000, 80000), borderwidth=100,\ rgb=0xff, borderrgb=0x0, printname="t1",\ page=page, error=e) g =@ pf.addgraphic(printform1arc, point.new(86519, 206056), \ point.new(179917, 206321), \ printmidpoint=point.new(133350, 154198), \ borderwidth=100, rgb=0xff0000, \ borderrgb=0x0, printname="arc1", page=page, \ error=e) g =@ pf.addgraphic(printform1ellipse, \ point.new(68281, 229369), \ point.new(115113, 249213), \ printmidpoint=point.new(68281, 249213), \ borderwidth=100, rgb=0xff00ff, \ borderrgb=0x0, printname="ellipse1", page=page,\ error=e) // The image is 192x80 url = "http://www.simpol.com/images/style1/logo.png" bmp =@ retrievebitmap(url, "png", error=e) if bmp =@= .nul bmp =@ createblankbmp(192, 80, missing=.true, error=e) end if if bmp !@= .nul c =@ pf.addcontrol(printform1bitmap, 45000, 70000, 50800, \ 21167, bitmap=bmp, \ scaling="preserveaspect", page=page, \ error=e) end if s = "The quick brown fox jumped over the lazy dog. \ Peter Piper picked a peck of pickled peppers. How \ many pickled peppers did Peter Piper pick?" font =@ wxfont.new("Arial", 13, "n", "n", "", error=e) c =@ pf.addcontrol(printform1text, 40000, 130000, 90000, \ 35000, s, backgroundrgb=0x0, \ textrgb=0xffffff, printalignment="", \ font=font, printname="text123", \ page=page, error=e) pf.print(error=e) wxprocess(.inf) end if end function function quit(wxwindow me) wxbreak() end function
The preceding source code creates a window (just to keep the print preview
window open and the program running) and then create the print form. It adds one of each of
the graphic types to it (please note that coming up with valid coordinates for an arc or
ellipse is not trivial — these were converted from pixel values after drawing them using
the SIMPOL Form Designer in SIMPOL Personal). Following the graphics, an image is retrieved
from the Internet via the URL using the retrievebitmap()
function that
is part of the databaseforms.sml
library. If it fails
to retrieve a bitmap, it calls another function from the library to create a blank image with
an X through it in the same size, to act as a missing image replacement. It then adds the
bitmap to the print form. Finally it adds a text element with static text that is centered
both horizontally and vertically and display as white text on a black background. This is then
sent to the print preview window. Once the small main window is closed, the program ends.