问题:如何给button按钮加上颜色呢?

解决方案 »

  1.   

    var cvs:tcanvas;
    begin
    cvs:=tcanvas.create;
    cvs.handle:=getdc(button1.handle);
    //cvs.brush.color:=rgb(0,128,128);
    //cvs.FillRect(rect(2,2,button1.width-2,button1.height-2)); //画背景
    cvs.brush.style:=bsclear;
    cvs.font:=button1.font;
    cvs.font.color:=rgb(0,0,255);
    cvs.TextOut((button1.width-cvs.textwidth(button1.caption)) div 2,(button1.height-cvs.textheight(button1.caption)) div 2,button1.caption);
    end;
      

  2.   

    如楼上所说,将CANVAS的HANDLE设置为按钮,就可以画按钮的颜色了
    只是这样只能改变按钮表面的颜色,但单击按钮时还会成为原来按钮的
    颜色
    关注中!
      

  3.   

    你需要继承一个按钮,然后
    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls;type
      TButtonMy=class(TButton)
      private
        procedure demo(var Message: TMessage); message WM_Paint;
      public
        procedure Click; override;
      end;
      TForm1 = class(TForm)
        procedure FormCreate(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}
    procedure TButtonMy.demo(var Message: TMessage);
    var cvs:tcanvas;
    begin
     inherited;
     cvs:=tcanvas.create;
     cvs.handle:=getdc(self.handle);
     cvs.brush.color:=rgb(0,128,128);
     cvs.FillRect(rect(2,2,self.width-2,self.height-2)); //画背景
     cvs.brush.style:=bsclear;
     cvs.font:=self.font;
     cvs.font.color:=rgb(0,0,255);
     cvs.TextOut((self.width-cvs.textwidth(self.caption)) div 2,(self.height-cvs.textheight(self.caption)) div 2,self.caption);
    end;
    procedure TButtonMy.Click;
    var
      Form: TCustomForm;
    begin
      Form := GetParentForm(Self);
      if Form <> nil then Form.ModalResult := ModalResult;
      inherited Click;
      SendMessage(self.Handle,wm_paint,0,0);
    end;
    procedure TForm1.FormCreate(Sender: TObject);
    var but:TButtonMy;
    begin
      but:=TButtonMy.Create(nil);
      but.ParentWindow :=form1.Handle ;
      but.Show ;
    end;end.
      

  4.   

    你要写这么多程序还不如直接用BitBtn好的多!!!!