再三求教!!button问题!!

vargent77 2003-10-09 10:28:01
我需要的大概就是:
---------------
| | 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;
...全文
175 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
vargent77 2003-10-16
  • 打赏
  • 举报
回复
结贴了,问题暂时解决!代码大概如下,可惜还是有问题!
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]);
vargent77 2003-10-14
  • 打赏
  • 举报
回复
上面的问题解决了,但来了后遗症,有出现了这个问题http://expert.csdn.net/Expert/topic/2352/2352430.xml?temp=.2960169
Alanwn 2003-10-09
  • 打赏
  • 举报
回复
没办法,不会
snowfog 2003-10-09
  • 打赏
  • 举报
回复
关注
vargent77 2003-10-09
  • 打赏
  • 举报
回复
来帮忙啊各位
fengyvn 2003-10-09
  • 打赏
  • 举报
回复
呵呵,思路正确,注意一下细节就行了.
pressman 2003-10-09
  • 打赏
  • 举报
回复
呵呵,恭喜你解决了!
cow8063 2003-10-09
  • 打赏
  • 举报
回复
解决了,呵,那来要分了,
da_yu 2003-10-09
  • 打赏
  • 举报
回复
vargent77(地平线) 老兄,你既然解决了,就该放出来让大家也学习学习呀——想想
自己求救时抓耳挠腮的样子?
FrameSniper 2003-10-09
  • 打赏
  • 举报
回复
没时间回答这么多内容的问题了!
vargent77 2003-10-09
  • 打赏
  • 举报
回复
^_^,终于解决了,好开心
vargent77 2003-10-09
  • 打赏
  • 举报
回复
各位高手,给点帮助好啊

5,392

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧