I need to print a rectangle round some TppLabel.Caption. I tried the using TppLabel.Width but this isn't very accurate. The rectangles width has to be the TextWidth(TppLabel.Caption) + 10. How do I do this in reportbuilder?
You can try using the TCanvas.TextWidth routine in Delphi. The canvas of a TBitmap will give you the width in screen pixels and the Printer.Canvas will it to you in printer pixels. Then you will need to convert that value into your own measurement units.
Comments
You can try using the TCanvas.TextWidth routine in Delphi. The canvas of a
TBitmap will give you the width in screen pixels and the Printer.Canvas will
it to you in printer pixels. Then you will need to convert that value into
your own measurement units.
--
Regards,
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com
It won't work. The calculated length is always short. I get the same results
using both bitmap/printer methods. What's wrong?
TppChildReport.Units = utScreenPixels
ABitMap := TBitMap.Create;
try
ABitMap.Canvas.Font.Style := ppAYPLDOS_OMS_PLC.Font.Style;
ABitMap.Canvas.Font.Name := ppAYPLDOS_OMS_PLC.Font.Name;
ppAYPLDOS_LINE_PLC.Width :=
ABitMap.Canvas.TextWidth(ppAYPLDOS_OMS_PLC.Caption);
ppline.Width := ABitMap.Canvas.TextWidth(ppAYPLDOS_OMS_PLC.Caption);
ppbox.Width := ABitMap.Canvas.TextWidth(ppAYPLDOS_OMS_PLC.Caption);
finally
FreeAndNil(ABitMap);
end;
TppChildReport.Units = utPrinterPixels
TppChildReport.Printer.Canvas.Font.Style := ppAYPLDOS_OMS_PLC.Font.Style;
TppChildReport.Printer.Canvas.Font.Name := ppAYPLDOS_OMS_PLC.Font.Name;
ppline.Width :=
TppChildReport.Printer.Canvas.TextWidth(ppAYPLDOS_OMS_PLC.Caption);
ppbox.Width :=
TppChildReport.Printer.Canvas.TextWidth(ppAYPLDOS_OMS_PLC.Caption);
Greetings,
Filip Moons
TppLabel exactly (printer and screen).
uses
ppPrintr,
ppUtils,
ppTypes;
procedure TForm1.ppHeaderBand1BeforePrint(Sender: TObject);
var
liTextWidth: Integer;
liTextWidthMM: Integer;
lCanvas: TCanvas;
begin
lCanvas := ppPrinter.Canvas;
lCanvas.Font := ppLabel1.Font;
liTextWidth := lCanvas.TextWidth(ppLabel1.Text);
liTextWidthMM := ppToMMThousandths(liTextWidth, utPrinterPixels,
pprtHorizontal, ppPrinter);
ppLine1.Width := ppFromMMThousandths(liTextWidthMM, utInches,
pprtHorizontal, ppPrinter);
end;
--
Regards,
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com
Greetings,
Filip Moons