Entwickler-Ecke

Grafische Benutzeroberflächen (VCL & FireMonkey) - Auf TSpeedButton zeichnen/schreiben


jjturbo - Di 20.01.09 14:50
Titel: Auf TSpeedButton zeichnen/schreiben
Moin Forum,

kann ich irgendwie auf einen TSpeedbutton neben der Caption einen weiteren Text ausgeben?
Ich benötige einen zweiten Text an anderer Position und mit einer anderen Schriftart.

Wenn ich das nur einmal bräuchte würde ich jetzt einfach ein TLabel drüberlegen, aber das geht doch bestimmt eleganter, oder?

Gruß jjturbo


jjturbo - Di 20.01.09 15:31

Habe eine Lösung gefunden:

Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
procedure TForm1.SpeedButtonsBeschriften(Btn:TSpeedButton;Txt1,Txt2:String;FontSize1,FontSize2:Integer);
var R         :TRect;
    PosX      :Integer;
    PosY      :Integer;
    txtHoehe  :Integer;
    txtBreite :Integer;
begin

  with Btn do begin
    Glyph.Height            := Height;
    Glyph.Width             := Width;
    Glyph.Canvas.Font       := Font;

    Glyph.Canvas.Font.Size  := FontSize1;
    R                       := Bounds(0,0,Glyph.Width,Glyph.Height);
    Glyph.Canvas.TextOut(0,0,Txt1);

    Glyph.Canvas.Font.Size  := FontSize2;
    txtHoehe                := Glyph.Canvas.TextHeight(Txt2);
    txtBreite               := Glyph.Canvas.TextWidth(Txt2);
    PosX                    := R.Right div 2 - txtBreite div 2;
    PosY                    := R.Bottom div 2 - txtHoehe div 2;
    Glyph.Canvas.TextOut(PosX,PosY,Txt2);
  end;

end;