Print Preview
Posted
#1
(In Topic #566)
Guru

I have looked at examples within Gambas, and it looks simple, but it's not working! Any ideas?
Using gb.gui.qt the following code brings up the form, but it's blank and the program crashes.
Using gb.gui the form is not seen and the program crashes.
Posted
Enthusiast

Posted
Regular

Maybe it (Preview method) is hanging up expecting something to be defined that wasn't yet.
/howto/print - Gambas Documentation
"You have to implement the draw event. All other events are optional."
Posted
Regular

Code (gambas)
- ' gambas class file
- 'by postapase
- TextArea1.Clear
- Paint.DrawRichText(DataAlinePrinter, PRINT_MARGIN, PRINT_MARGIN,,, Align.TopNormal)
- Me.Center
You can look at how I did it in the File Cabinet program in Project Showcase
Posted
Guru

Thanks for trying.I'm with today's 3.15.90 / gb.gui.qt and your code crashes gambas completely …
sjsepan
Thanks, but I can't work out what.Maybe it (Preview method) is hanging up expecting something to be defined that wasn't yet.
cage
Thanks. I have managed to get the print routine working, I just wanted to try the preview.Charlie here is an example that I use in my File Cabinet program that does work…..
The program prints on 1" (25.4mm) x 2" (50.8mm) labels. The main problem is that after 1 print of say 5 labels, the next print only prints 1, even though the 'No of copies' is set to 5.
If you want to see how the 'Preview' works just press [Ctrl] + P in the IDE.
The actual code I am using is: -
Code (gambas)
- Printer1.PaperHeight = 25.4
- Printer1.PaperWidth = 50.8
- Printer1.MarginBottom = 0
- Printer1.MarginTop = 0
- Printer1.MarginLeft = 0
- Printer1.MarginRight = 0
- Printer1.Print
- Paint.Begin(Printer1)
- hBrush = Paint.Color(Color.Black)
- Paint.DrawText(hCode[iPrint].Text, 0, iY1, 105, 20, Align.Center)
- Paint.DrawText(hLabels[iPrint].Text, 0, iY2, 105, 20, Align.Center)
- Paint.Stroke
- Paint.End
This is the output
<IMG src="https://www.cogier.com/gambas/barcode5.png">
</IMG>
Posted
Guru

For those who are interested try this code: -
It's very strange that this works as the 'Printer.Count' is 1 when it goes into the '_Begin' routine but without it it fails. :?
Posted
Trainee
Code
'Call a report preview from a form button
'snippet code only
Static Public $hReport As Report
Public Sub Button3_Click()
'print recipe preview from button click on form
'renew the report for each run
'report object name is "rptRecipe"
'Gambas IDE changes first letter of report name to upper case
$hReport = New RptRecipe
$hReport.Preview()
End
The report has a .class file that fleshes it out with data from tables and some pretty stuff. If you start doing printing and reports, plan to spend some time in the examples found on the farm, and elsewhere, and experiment a lot.
-Dave
1 guest and 0 members have just viewed this.


