再三求教!!button问题!!
我需要的大概就是:
---------------
| | caption:如CSDN |
| 图片 |------------------
| | text:如连接成功 |
----------------------------
这样的效果
下面我的代码,知道不少问题,希望各位给我点正确的代码!!!
unit SpeedButton1;
interface
uses
SysUtils, Classes, Controls, StdCtrls, Buttons,windows,Messages;
type
TBtn5 = class(TSpeedButton)
private
{ Private declarations }
FSpeedButton:TSpeedButton;
procedure Paintline(R:TRect;S:String);
protected
{ Protected declarations }
procedure SetGlyph(Value: TBitmap);
function GetGlyph: TBitmap;
//procedure SetOnButtonClick(Value:TNotifyEvent);
// function GetOnButtonClick:TNotifyEvent;
procedure SetText(Value:String);
function GetText:String;
//procedure SetFont(Value:TFont);
//function GetFont:TFont;
procedure SetCaption(Value:String);
function GetCaption:String;
procedure SetFont(Value:TFont);
function GetFont:TFont;
public
{ Public declarations }
constructor Create(AOwner:TComponent);override;
destructor Destroy;override;
published
{ Published declarations }
property OnButtonClick;//:TNotifyEvent read GetOnButtonClick write SetOnButtonClick;
//应该这里继承一下speedbutton的就可以了吧?
property Text: string read GetText write SetText; //这是我希望新增的属性
property Caption;
property Enabled;
property Font;
property Glyph:TBitmap read GetGlyph write SetGlyph; //这里是不是可以直接用speedbutton原有的呢?
end;
procedure Register;
implementation
constructor TBtn5.Create(AOwner: TComponent); //创建,设置各项属性
begin
inherited;
ControlStyle :=ControlStyle+[csOpaque];
Cursor :=crHandPoint;
Height :=30;
width :=60;
//Visible := False;
end;
procedure TBtn5.SetGlyph(Value: TBitmap);
begin
if FSpeedButton.Glyph<>Value then
FSpeedButton.Glyph.Assign(Value);
end;
function TBtn5.GetGlyph:TBitmap;
begin
Result:=FSpeedButton.Glyph;
end;
procedure TBtn5.SetText(Value:String); //写text属性
var
Text1Rect:TRect;
begin
TBtn5.Text:=Value;
Text1Rect:=Rect(30,0,60,15); //如上图,写在右上角
Paintline(Text1Rect,Self.Text);
end;
function TBtn5.GetText:String;
begin
Result:=TBtn5.Text;
end;
procedure TBtn5.SetCaption(Value:String); //写Caption属性
var
Text2Rect:TRect;
begin
TBtn5.Caption:=Value;
Text2Rect:=Rect(30,15,60,30); //如上图,写在右下角
Paintline(Text2Rect,TBtn5.Caption);
end;
function TBtn5.Getcaption:String;
begin
Result:=TBtn5.Caption;
end;
procedure TBtn5.Paintline(R:TRect;S:String); //用DrawText写
const
Flags:Array[Tjustification] of DWORD = (DT_CENTER,DT_LEFT,DT_RIGHT);
var
S:String;
TextRect:TRect;
begin
InvalidateRect(Handle,@R,False); //只画对应的区域
DrawText(Canvas.Handle,PChar(S),length(S),TextRect,
Flags[FJust]);
end;
destructor TBtn5.Destroy;
begin
inherited Destroy;
end;
procedure Register;
begin
RegisterComponents('Samples', [TBtn5]);
end;