Forum > General
DrawText for multiline button caption failure
anna:
--- Quote from: theo on April 04, 2010, 12:41:50 pm ---
--- Quote from: anna on April 04, 2010, 11:56:51 am ---It does't work. All text is in one line regardless of length of words.
--- End quote ---
Yes, Sorry it works for GTK2.
You could try this for windows but I don't know if it works on other WS:
--- Code: ---procedure TForm1.FormCreate(Sender: TObject);
var S: AnsiString;
R: TRect;
stl:TTextStyle;
begin
S:='Hello World Hello World Hello World Hello World';
BitBtn1.Glyph.Canvas.Font := BitBtn1.Font;
BitBtn1.Glyph.Width := BitBtn1.Width - 6;
BitBtn1.Glyph.Height := BitBtn1.Height - 6;
R := Bounds(0, 0, BitBtn1.Glyph.Width, BitBtn1.Glyph.Height);
BitBtn1.Caption := '';
BitBtn1.Glyph.Transparent:=false;
BitBtn1.Glyph.Canvas.Brush.Color:=clBtnFace;
BitBtn1.Glyph.Canvas.FillRect(R);
stl.Alignment:=taCenter;
stl.Wordbreak:=true;
stl.Layout:=tlCenter;
stl.SingleLine:=false;
R := Bounds(1, 1, BitBtn1.Glyph.Width-1, BitBtn1.Glyph.Height-1);
BitBtn1.Glyph.Canvas.TextRect(R,0,0,S,stl);
end;
--- End code ---
--- End quote ---
Thank you for listing. How to define size of text to be written by TextRect ?
Next operators don't work:
BitBtn1.Glyph.Canvas.Font.Size:=6;
BitBtn1.Glyph.Canvas.Font.Height:=6;
I monitored TextHeight(S) method before TextRect and was surprised that it's 13 for unknown reasons.
Navigation
[0] Message Index
[*] Previous page