Forum > General
DrawText for multiline button caption failure
anna:
On my form i have only BitBtn4. For Form OnCreate event I've written:
--- Code: ---procedure TForm1.FormCreate(Sender: TObject);
var S: AnsiString;
R: TRect;
begin
with BitBtn4 do
begin
S:=Caption;
Glyph.Canvas.Font := Self.Font;
Glyph.Width := Width - 6;
Glyph.Height := Height - 6;
R := Bounds(0, 0, Glyph.Width, 0);
Caption := '';
DrawText(Glyph.Canvas.Handle,PChar(S),Length(S),R,
DT_CENTER or DT_WORDBREAK or DT_CALCRECT);
OffsetRect(R,(Glyph.Width - R.Right) div 2,
(Glyph.Height - R.Bottom) div 2);
DrawText(Glyph.Canvas.Handle,PChar(S),Length(S),R,
DT_CENTER or DT_WORDBREAK);
end;
end;
--- End code ---
But I saw a black rectangle. If I add Glyph.Mask(0);
I see text in white background, but characters have poor look.
--- Code: ---..............
Glyph.Mask(0);
end;
end;
--- End code ---
I need transparent background, well-look black multiline text and no black rectangle. I need a same look as TButton. How to do it?
If there is simpler way to do multiline caption in button - write me.
theo:
--- Quote from: anna on April 04, 2010, 10:46:32 am ---I need a same look as TButton. How to do it?
If there is simpler way to do multiline caption in button - write me.
--- End quote ---
You could take a TButton and Insert the break position yourself.
Like: Button1.Caption:='Hello'+LineEnding+'World';
anna:
--- Quote from: theo on April 04, 2010, 11:39:13 am ---
--- Quote from: anna on April 04, 2010, 10:46:32 am ---I need a same look as TButton. How to do it?
If there is simpler way to do multiline caption in button - write me.
--- End quote ---
You could take a TButton and Insert the break position yourself.
Like: Button1.Caption:='Hello'+LineEnding+'World';
--- End quote ---
It does't work. All text is in one line regardless of length of words.
typo:
I think you should draw a bitmap with the desired text and use a SpeedButton to show it.
anna:
--- Quote from: typo on April 04, 2010, 12:20:46 pm ---I think you should draw a bitmap with the desired text and use a SpeedButton to show it.
--- End quote ---
What's the difference? Just now I test my project with SpeedButton instead of BitBtn - see black rectangle. Problems remain same.
Navigation
[0] Message Index
[#] Next page