tppLabel - retrieving size dynamically.
Hi
I have a tppLabel that has it's font size and caption set by my code. I
then have a tppShape forming a border around it and a number of other
componenets that position themselves on the report depending on the
dimensions and position of the Label.
The problem is that although the tppLabel does expand to display the
caption in the font I set, the width and height of the label don't seem
to change imediately after I change the font and caption(I don't know
when they do change, but they do at some stage). Therefore the border I
place around the label is the incorrect size and components I place
around are not placed correctly.
Does anyone now the cause or a way around this problem.
Thanks
Andrew
I have a tppLabel that has it's font size and caption set by my code. I
then have a tppShape forming a border around it and a number of other
componenets that position themselves on the report depending on the
dimensions and position of the Label.
The problem is that although the tppLabel does expand to display the
caption in the font I set, the width and height of the label don't seem
to change imediately after I change the font and caption(I don't know
when they do change, but they do at some stage). Therefore the border I
place around the label is the incorrect size and components I place
around are not placed correctly.
Does anyone now the cause or a way around this problem.
Thanks
Andrew
This discussion has been closed.
Comments
If you are updating the font size in code the width of the label will not
ever be updated in the TppLabel component before printing. This measurement
is made in the draw command before sending it to the printer device.
In order to address this issue, you have two options.
1. Upgrade to ReportBuilder 9.01. RB 9.01 natively supports borders for
all text components that will grow and shrink as the text does on your
report automatically.
2. You can use the TCanvas.TextWidth function to find out the approximate
width of a label after setting the TCanvas.Font property to the correct
settings. Using this width, you can size and position your shape before the
object is generated.
--
Regards,
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com
You can use the result to adjust the left position of your control.
Additionally it maybe a starter for something similar adjusting
height/top....
Cheers
Bernd
procedure TComponentGetRightEnd.ExecuteFunction(aParams: TraParamList);
var
lCustomText: TppCustomText;
lBitmap : TBitmap;
aComponent : TComponent;
liTextWidth: Integer;
liPosition : Integer;
begin
// Calling code must use spLeft:=GetRightEnd(..) to adjust properly
GetParamValue(0,aComponent);
lCustomText:=TppCustomText(aComponent);
lBitmap:=TBitmap.Create;
lBitmap.Canvas.Font:=lCustomText.Font;
liTextWidth:=lBitmap.Canvas.TextWidth(lCustomText.Text);
liPosition:=lCustomText.spLeft+liTextWidth;
lBitmap.Free;
SetParamValue(1,liPosition);
end;
class function TComponentGetRightEnd.GetSignature : string;
begin
Result:='function ComponentGetRightEnd(aComponent:TComponent): Integer;';
end;
....
raRegisterFunction('ComponentGetRightEnd',TComponentGetRightEnd);
.....
raUnRegisterFunction('ComponentGetRightEnd');