How to stretch summary lines?
Hello,
in my TppSummaryBand I have two controls: A TppDBCalc and a TppLine. The
width of the TppLine should depend on the width of the TppDBCalc, which also
depends on the values in the underlying data set.
I have had a look at the "Moving Labels" project (Message-ID:
<3f8d73f4$1@dm500.>), but that helped only slightly.
At the moment, my code looks like this (the TppDBCalc has the property
AutoSize set to TRUE and the property TextAlignment set to
taRightJustified).
procedure TFrameTemplateReportFrame.UpdateSummaryLine(ALine, ASource:
TppPrintable);
const
Buffer = 10; //the line should begin 10 points before the TppDBCalc and
end 10 points behind the TppDBCalc
var
TextWidth: Single;
TextRight: Single;
begin
TextWidth := ppPrinter.Canvas.TextWidth(ASource.Text); //that should
compute the width of the TppDBCalc, but it seems to me that the calculated
width is greater than expected. Why that?
TextRight := ASource.Left + ASource.Width;
ALine.Left := TextRight - TextWidth - Buffer;
ALine.Width := TextWidth + Buffer * 2;
end;
Can you give me a hint, what I am doing wrong? I don't really get it at the
moment.
Thanks very much!
Mike
in my TppSummaryBand I have two controls: A TppDBCalc and a TppLine. The
width of the TppLine should depend on the width of the TppDBCalc, which also
depends on the values in the underlying data set.
I have had a look at the "Moving Labels" project (Message-ID:
<3f8d73f4$1@dm500.>), but that helped only slightly.
At the moment, my code looks like this (the TppDBCalc has the property
AutoSize set to TRUE and the property TextAlignment set to
taRightJustified).
procedure TFrameTemplateReportFrame.UpdateSummaryLine(ALine, ASource:
TppPrintable);
const
Buffer = 10; //the line should begin 10 points before the TppDBCalc and
end 10 points behind the TppDBCalc
var
TextWidth: Single;
TextRight: Single;
begin
TextWidth := ppPrinter.Canvas.TextWidth(ASource.Text); //that should
compute the width of the TppDBCalc, but it seems to me that the calculated
width is greater than expected. Why that?
TextRight := ASource.Left + ASource.Width;
ALine.Left := TextRight - TextWidth - Buffer;
ALine.Width := TextWidth + Buffer * 2;
end;
Can you give me a hint, what I am doing wrong? I don't really get it at the
moment.
Thanks very much!
Mike
This discussion has been closed.
Comments
When using the printer canvas you are calculating the width in printer
pixels rather than report units you are setting the line properties with.
You also need to be sure you set the Canvas.Font property to the font you
are using in your text component. My suggestion would be to convert
everything to microns using the ppToMMThousandths method (located in the
ppUtils.pas file), then converting back to the report units you are using.
Using the printer canvas is probably your best option to ensure the highest
quality precision when printing. For instance, you might do something like
the following:
uses
ppPrintr,
ppUtils,
ppTypes;
...
var
lTextWidth: Single;
liTextWidthPP: Integer;
liTextWidthMM: Integer;
begin
ppPrinter.Canvas.Font := Label.Font;
liTextWidthPP := ppPrinter.Canvas.TextWidth(Label.Text);
liTextWidthMM := ppToMMThousandths(liTextWidthPP, utPrinterPixels,
pprtHorizontal, ppPrinter);
lTextWidth := ppFromMMThousandths(liTextWidthMM, utInches,
pprtHorizontal, ppPrinter);
Line.Left := Label.Left;
Line.Width := lTextWidth;
end;
--
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com
highest
like
Thanks for your help. It works perfectly!
Mike :-)