[Gambas-user] About Printer
Benoît Minisini
gambas at ...1...
Tue Jul 19 14:43:15 CEST 2011
> i want to print a rectangle on a page.
>
> i have this code:
>
> ----------------
> ' Gambas class file
>
> Private Const PAPER_FACTOR As Float = 7.55
>
> Public Sub btnPrint_Click()
>
> If prtPrinter.Configure() Then Return
>
> Me.Enabled = False
> Inc Application.Busy
> prtPrinter.Print
> Dec Application.Busy
> Me.Enabled = True
>
> End
>
> Public Sub prtPrinter_Draw()
>
> Dim X As Float
> Dim Y As Float
> Dim W As Float
> Dim H As Float
> Dim wFactor As Float
> Dim hFactor As Float
>
> txtArea.Text &= "Begin Draw\n"
>
> 'Set scale
> wFactor = prtPrinter.PaperWidth / Paint.Width
> hFactor = prtPrinter.PaperHeight / Paint.Height
> Paint.Scale(wFactor, hFactor)
>
> 'Set Color to red
> Paint.Color(Color.RGB(255, 0, 0, 0))
>
> 'Set X,Y margin to 0,0
> X = 0
> Y = 0
>
> 'W points * 7.55 = W mm
> 'W = 100 = 100 mm = 10 cm
> W = 200 * PAPER_FACTOR
> H = 100 * PAPER_FACTOR
>
> 'Draw a rectangle
> Paint.Rectangle(X, Y, W, H)
>
> 'Write it on paper
> Paint.Stroke
>
> End
>
> ------------------
>
> At the beginning i make a scale
> Paint.Scale(wFactor, hFactor)
>
> according to page
> http://gambasdoc.org/help/howto/print?v3
>
> to have absolute coordinates.
>
> Problem #1
> -----------
> i want the rectangle to be printed at (x,y) = (0,0)
> so i set
>
> 'Set X,Y margin to 0,0
> X = 0
> Y = 0
>
> But at the page it is printed 46 points inside and lower.
> If i use
> X = -46
> Y = -46
>
> i get the rectangle at the beginning of page, straight to border.
You must set the FullPage to print on the entire page. Otherwise margins will
be taken into account.
>
> Problem #2
> -----------
> i want to set width to 100 millimeters. I found that i have to multiply
> the number in millimeters with 7.55 so i use this as constant
> PAPER_FACTOR
>
> How really does this work? why this number?
You shouldn't. Can you print the values of prtPrinter.PaperWidth,
prtPrinter.PaperHeight, Paint.Width, Paint.Height, wFactor, hFactor...?
>
> Problem #3
> -----------
> 'Set Color to red
> Paint.Color(Color.RGB(255, 0, 0, 0))
>
> color does not work on printing i get black lines
Paint.Color creates a brush that you must assign to the Paint.Brush property:
Paint.Brush = Paint.Color(Color.RGB(255, 0, 0, 0))
Regards,
--
Benoît Minisini
More information about the User
mailing list