Subject | Re: [IBO] IB_LookupCombo.TextWidth |
---|---|
Author | Markus Ostenried |
Post date | 2001-08-20T11:48:42Z |
Hi Geoff,
At 12:11 20.08.2001 +1000, you wrote:
FComboCanvas: TCanvas;
...
FComboCanvas := TCanvas.Create;
// assign the font of the first LookupCombo
FComboCanvas.Font.Assign( FNodeSels[0].LCNode.Font );
...
procedure TW_TifEdit_NodeSel.NSAdjustWidth( AIdx: Integer );
var
sText: String;
tw : Integer;
begin
sText := FNodeSels[AIdx].QryLkNode.FieldByName( 'TN_TEXT' ).AsString;
tw := FComboCanvas.TextWidth( sText ) + 6; // <-- EInvalidOperation
// the following doesn't work, too: Compiler error "Identifier Canvas
not found"
// tw := FNodeSels[AIdx].LCNode.Canvas.TextWidth( sText ) + 6;
FNodeSels[AIdx].LCNode.Width := Max( 20, tw );
end;
Can't TIB_LookupCombo.FCanvas be made public ?
// make Button invisible
for i := 0 to LCNode.ComponentCount-1 do begin
if (LCNode.Components[i] is TIB_ComboButton) then begin
ComboBtn := TIB_ComboButton( LCNode.Components[i] );
ComboBtn.Width := 0;
ComboBtn.Parent.Visible := false;
Break;
end;
end;
I looked into the Combo sources and noticed that the focus rect is
calculated by
ARect := ClientRect;
Dec( ARect.Right, FButton.Width );
So I set "ComboBtn.Width := 0;" and "ComboBtn.Parent.Visible := false;".
The Parent is a TWinControl. This works fine.
Thanks,
Markus
At 12:11 20.08.2001 +1000, you wrote:
> > But this gives me the wrong result. Does anyone knowI tried it but I get EInvalidOperation "Canvas does not allow drawing":
> > how to get the exact width ?
>
>Generally you can just use the Form's Canvas property for such
>calculations - depending on whether you have changed the font in your
>controls. If you have changed the font I am wondering whether you
>should be just using a TCanvas (not a TControlCanvas - I am not
>certain but there are some device context issues when using
>TControlCanvas). Create a TCanvas, assign the font from the control
>and then do the width calculation.
FComboCanvas: TCanvas;
...
FComboCanvas := TCanvas.Create;
// assign the font of the first LookupCombo
FComboCanvas.Font.Assign( FNodeSels[0].LCNode.Font );
...
procedure TW_TifEdit_NodeSel.NSAdjustWidth( AIdx: Integer );
var
sText: String;
tw : Integer;
begin
sText := FNodeSels[AIdx].QryLkNode.FieldByName( 'TN_TEXT' ).AsString;
tw := FComboCanvas.TextWidth( sText ) + 6; // <-- EInvalidOperation
// the following doesn't work, too: Compiler error "Identifier Canvas
not found"
// tw := FNodeSels[AIdx].LCNode.Canvas.TextWidth( sText ) + 6;
FNodeSels[AIdx].LCNode.Width := Max( 20, tw );
end;
Can't TIB_LookupCombo.FCanvas be made public ?
>Have you allowed for the width of the button on the lookup?No, I do this (becaus the ComboBtn is a private member of TIB_LookupCombo):
// make Button invisible
for i := 0 to LCNode.ComponentCount-1 do begin
if (LCNode.Components[i] is TIB_ComboButton) then begin
ComboBtn := TIB_ComboButton( LCNode.Components[i] );
ComboBtn.Width := 0;
ComboBtn.Parent.Visible := false;
Break;
end;
end;
I looked into the Combo sources and noticed that the focus rect is
calculated by
ARect := ClientRect;
Dec( ARect.Right, FButton.Width );
So I set "ComboBtn.Width := 0;" and "ComboBtn.Parent.Visible := false;".
The Parent is a TWinControl. This works fine.
> > My second problem is to find an event when to adjust the width.I'll try it.
> > I tried ComboBox.OnCloseUp but when this event occurs then
> > sometimes
> >
> > FQryLkNode.FieldByName('TNR_ID_NODEREL').IsNull = true;
> >
> > I guess that during this event the Dataset is scrolling
> > and therefor has no current record. "AfterScroll" fires
> > too often. Is there a better event for this ?
>
>Not sure about this, have you tried the TIB_DataSource.OnDataChange
>event?
Thanks,
Markus