我需要的大概就是:
---------------
|       |  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;

解决方案 »

  1.   

    vargent77(地平线) 老兄,你既然解决了,就该放出来让大家也学习学习呀——想想
    自己求救时抓耳挠腮的样子?
      

  2.   

    上面的问题解决了,但来了后遗症,有出现了这个问题http://expert.csdn.net/Expert/topic/2352/2352430.xml?temp=.2960169
      

  3.   

    结贴了,问题暂时解决!代码大概如下,可惜还是有问题!
     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]);