Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2013-11

Fit TFrom's width so that it's caption isn't cut off?

4 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Avishai
to Bart

I used this code to AutoSize a TMemo but you might be able to modify it for your needs. The problem I see is that TForm.Caption.Font is not effected by the TForm.Font. Maybe set the Font to default in the routine.
------------

function GetTextHeight(ACtrl: TControl): Integer;
var
  C: TBitMap;
begin
  Result:= -1;
  C := TBitmap.Create;
  try
    C.Canvas.Font.Assign(ACtrl.Font);
    Result:= C.Canvas.TextHeight('TextHeight');
  finally
    C.Free;
  end;
end;
procedure TForm1.BitBtn3Click(Sender: TObject);
var
  H: Integer;
begin
  H:= GetTextHeight(Memo1);
  If H>-1 then
    Memo1.Height:= (H*Memo1.Lines.Count)+H div 2;
end;
Bart wrote 15 lines
Hi all, Is there a crossplatform way to determine the necessary width for a TForm so that it's caption wont be cut off? It does have to work regardless of the (amount of) bordericons the form has. NB. Needed for http://bugs.freepascal.org/view.php?id=19637 Bart -- _______________________________________________ Lazarus mailing list http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Shalom, Avishai ????? ????

Reply by email

Bart
to Avishai
Avishai wrote 14 lines
function GetTextHeight(ACtrl: TControl): Integer; var C: TBitMap; begin Result:= -1; C := TBitmap.Create; try C.Canvas.Font.Assign(ACtrl.Font); Result:= C.Canvas.TextHeight('TextHeight'); finally C.Free; end; end;

Is the canvas of the area where the caption is drawn the same as TForm's canvas, and is the font the same? I have no idea. And it does not take the bordericons into account.

Bart

Reply by email

Avishai
to Bart

I wish I knew the answer to your questions but I don't. I was only thinking that with the Text.Width you might be able to figure out an answer. I don't see how you could do it without that information, but maybe there is better way.

Bart wrote 28 lines
On 11/17/13, Avishai wrote: > function GetTextHeight(ACtrl: TControl): Integer; > var > C: TBitMap; > begin > Result:= -1; > C := TBitmap.Create; > try > C.Canvas.Font.Assign(ACtrl.Font); > Result:= C.Canvas.TextHeight('TextHeight'); > finally > C.Free; > end; > end; > Is the canvas of the area where the caption is drawn the same as TForm's canvas, and is the font the same? I have no idea. And it does not take the bordericons into account. Bart -- _______________________________________________ Lazarus mailing list http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Shalom, Avishai ????? ????

Reply by email