http://it.china-b.com/cxsj/delphi/20090820/146341_1.html

 

unit Unit12;

interface

uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.Buttons;

type
TForm12 = class(TForm)
Button1: TButton;
Button2: TButton;
BitBtn1: TBitBtn;
procedure Button2Click(Sender: TObject);

private
{ Private declarations }
public
{ Public declarations }
procedure SetCaption(AButton: TButton; ACaption1,ACaption2: string;color:TColor);
end;

var
Form12: TForm12;

implementation

{$R *.dfm}
uses System.Types;

procedure TForm12.Button2Click(Sender: TObject);
begin
//self.BitBtn1 .Caption:='aa'+#13+'bbb';
SetCaption(button1,'第一行','第二行',clred);
end;

procedure TForm12.SetCaption(AButton: TButton; ACaption1,ACaption2: string;color:TColor);

var

dc:Hdc;

info:tagsize;

begin

AButton.Caption:='';

dc:=GetDC(AButton.Handle);

SetBKColor(dc,color);

SetBkMode(dc,TRANSPARENT);

GetTextExtentPoint32(dc,pchar(ACaption1),length(ACaption1),info);

Textout(dc,AButton.Width div 2-info.cx div 2,AButton.Height div 2-info.cy,pchar(ACaption1),length(ACaption1));

GetTextExtentPoint32(dc,pchar(ACaption2),length(ACaption2),info);

TextOut(dc,AButton.width div 2-info.cx div 2,AButton.Height div 2,pchar(ACaption2),length(ACaption2));

end;


end.