关于按钮的caption(100分)

  • 主题发起人 主题发起人 jonyhuang
  • 开始时间 开始时间
哈哈。。。。。
你可以用一个图片当作按钮嘛。
爱写多少就写多少,
按钮的属性timage一般都有;
只是编程繁一些而已。
莫非你非要Button不可。
 
谁说不可以?一个演示而已:
procedure TForm1.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,AButton.Height div 2,pchar(ACaption2),length(ACaption2));
end;
 
kingron:
请问你这段程序写在那里,我无法运行阿,能否再说清楚点,行了我给分!谢谢!
jonghuang
 
我只是举一个例子而已!
不知道我也没有办法了。
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;

type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
procedure SetCaption(AButton: TButton; ACaption1,ACaption2: string;color:TColor);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
begin
SetCaption(button1,'First Line','Second Line',clred);
end;

procedure TForm1.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.
 
谢谢你,我已搞好,在请教一下,Ttoolbutton呢,又怎样,我试了一下改你的程序
在 dc:=GetDC(AButton.Handle);这里出错,请帮帮我,搞好我再加你分(200分)
jonyhuang
 
ToolBar的应该继承一个!如果采用原来的方法,不太好:
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ComCtrls, ToolWin;

type
TForm1 = class(TForm)
ToolBar1: TToolBar;
ToolButton1: TToolButton;
ToolButton2: TToolButton;
ToolButton3: TToolButton;
Button1: TButton;
procedure Button1Click(Sender: TObject);
procedure SetCaption(AToolBar: TToolBar;AButton:TToolButton;ACaption1,ACaption2: string;color:TColor);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
begin
SetCaption(ToolBar1,ToolButton2,'First','Second',clred);
end;

procedure TForm1.SetCaption(AToolBar: TToolBar;AButton:TToolButton;ACaption1,ACaption2: string;color:TColor);
var
dc:Hdc;
info:tagsize;
begin
dc:=AToolbar.Canvas.Handle;
SetTextColor(dc,Color);
SetBkMode(dc, TRANSPARENT);
GetTextExtentPoint32(dc,pchar(ACaption1),length(ACaption1),info);
AToolBar.Canvas.TextOut(AButton.Left+AButton.Width div 2-info.cx div 2,AButton.Top+AButton.Height div 2-info.cy,pchar(ACaption1));
GetTextExtentPoint32(dc,pchar(ACaption2),length(ACaption2),info);
AToolBar.Canvas.TextOut(AButton.Left+AButton.width div 2-info.cx div 2,AButton.Top+AButton.Height div 2,pchar(ACaption2));
end;

end.

 
用BITBTN就OK了。
 
后退
顶部