[Gambas-user] Paint.Begin(<object>) and printer.print

Rolf-Werner Eilert eilert-sprachen at ...221...
Wed Jan 9 10:19:10 CET 2013



Am 09.01.2013 10:03, schrieb Benoît Minisini:
> Le 09/01/2013 08:59, Rolf-Werner Eilert a écrit :
>>
>>
>> Am 08.01.2013 22:46, schrieb Karl Reinl:
>>> Salut,
>>>
>>> is that logical?
>>> For Paint.Begin(<object>) I need a device object.
>>> But if i start a printer with .print, Paint hijacks the printer as
>>> device.
>>> Had some day with blanc pages, while  setting Paint.Begin(<printer>) in
>>> printer_Begin().
>>> What worked when project is started as executable, but not when used as
>>> library.
>>>
>>
>> Salut Karl,
>>
>> This has caused me some headache before I finally understood that the
>> printer thing now runs completely in its own event loop, but graphics do
>> not.
>>
>> As far as I understand the mechanism, for graphics you still need to
>> point to a device and Paint (or Draw) into it. So you have to define a
>> Begin and End for it within your code. For printers, you simply set the
>> defaults and then start the event loop by saying Printer.Start. The
>> event loop will then touch the appropriate parts in the code by itself.
>>
>> This cleans up code, but it requires you to keep track of the page you
>> are currently in so you can print each content. I'm still working on
>> this one.
>>
>> The drawback is that you cannot simply re-use the same code parts for
>> either printing OR painting into a preview window for example. I haven't
>> solved this problem yet.
>>
>> But maybe I misunderstood your question completely, then simply ignore
>> this :-)
>>
>> Rolf
>>
>
> I don't see the problem. Why don't you proceed the following way?
>
> ------------------------------------------------------------
>
> ' Real printing
> ' The printer object is stored in the prnPrint variable
>
> Public Sub btnPrint_Click()
>
>     prnPrint.Print
>
> End
>
> ...
>
> Public Sub prnPrint_Begin()
>
>     ' Set the number of pages
>     prnPrint.Count = ...
>
> End
>
> Public Sub prnPrint_Draw()
>
>     ' Scale the preview so that you use the same coordinates for
>     ' printing and drawing
>     Paint.Scale(...)
>     DrawPage(prnPrint.Page)
>
> End
>
> ------------------------------------------------------------
>
> ' Preview
> ' Drawn inside a DrawingArea named dwgPreview.
> ' A SpinBox control named spnPage represents the current page to view.
>
> Public Sub dwgPreview_Draw()
>
>     ' Scale the preview so that you use the same coordinates for
>     ' printing and drawing
>     Paint.Scale(...)
>     DrawPage(spnPage.Value)
>
> End
>
> ------------------------------------------------------------
>
> ' The common drawing routine
>
> Public Sub DrawPage(Page As Integer)
>
>     Paint.DrawText("Hello world", 100, 100)
>     ...
>
> End
>


Uuuuh - brilliant :-) Thanks so much!

I'll print that out and care about it as soon as I return to that work. 
Currently too busy with our website...

Regards

Rolf




More information about the User mailing list