我需要的大概就是:
---------------
| | caption:如CSDN |
| 图片 |------------------
| | text:如连接成功 |
----------------------------
这样的效果
下面我的代码,知道不少问题,希望各位给我点正确的代码!!!
unit SpeedButton1;interfaceuses
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;implementationconstructor 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;
---------------
| | caption:如CSDN |
| 图片 |------------------
| | text:如连接成功 |
----------------------------
这样的效果
下面我的代码,知道不少问题,希望各位给我点正确的代码!!!
unit SpeedButton1;interfaceuses
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;implementationconstructor 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;
解决方案 »
- 求救啊~~~~~
- 最简单的问题 radiogroup 的使用
- 初学者问题:我写了一个函数:function StrToRMB(curs :string) :string; 请问如何声明,在哪里声明,如何调用。谢谢!只有30分了
- 如何用dll制作封装远程数据模块?!
- 求教,如何在win2000下屏蔽Ctrl+Alt+Del
- treeview动态添加问题 在线等待
- 汇总的问题!100分!
- 如何按 春-夏-秋-冬 排序?
- ???我如何发送 Ctrl+W 消息?有分!!!!!
- 急急急急!!!字符串位移加密解密(shl,shr)的算法及实现技术(字符处理)
- 有关SQL语句的问题!急!!!在线等待!!!
- 请高手把下面一段转换成Delphi语言,在线等待....
自己求救时抓耳挠腮的样子?
TextRect1:=Rect(Glyph.Width,0,self.ClientWidth,(self.ClientHeight div 2));
DrawText(Canvas.Handle,PChar(FText),length(FText),TextRect1,Flags[FAlignment]);
TextRect1:=Rect(Glyph.Width,(self.ClientHeight div 2),self.ClientWidth,self.ClientHeight);
DrawText(Canvas.Handle,PChar(FText1),length(FText1),TextRect1,Flags[FAlignment]);