想在Shape、SpeedButton上标写号码,用Canvas->TextOutA()写,但是它们没有Canvas,可以New一个吗?不要告诉我在Shape、SpeedButton上加Label,因为加了以后有其他麻烦.

解决方案 »

  1.   

    TCanvas *c;
        Graphics::TBitmap *BMP=new Graphics::TBitmap;
        BMP->LoadFromFile("F:\\My Pictures\\112.bmp");
        c = new TControlCanvas();
        ( (TControlCanvas *)c )->Control=Panel1;
        c->Brush->Style=bsClear;
        c->Pen->Color=clBlue;
        c->Rectangle(5,5,15,15);
        c->Draw(0,0,BMP);
        delete c;
        delete BMP;
    参考这个
      

  2.   

    用GetDC函数取上下文的DC句柄,用api函数画图
    或者就重载它的erasebkgnd函数,收到此消息时lparam就是dc句柄的值,用它来画图就行了
      

  3.   

    var
      c:TControlCanvas;
    begin
      c:=TControlCanvas.Create;
      try
        c.Control:=Shape1;
        c.TextOut(5,5,'Test');
      finally
        c.Free;
      end;
    end;
      

  4.   

    Shape没有OnPaint事件,一动画上去的字就没了!!
      

  5.   

    试试alexanda2000(Delphi2005,好用 ^_^)的,动态建立一个。
      

  6.   

    或者你从TShape继承一个类:  TMyShape = class(TShape)
      public
        Str:String;            //要显示的文字
        procedure MyPaint(var Msg:TMessage);Message WM_PAINT;
      end;然后修改相应代码:var
      Form1: TForm1;
      MyShape:TMyShape;implementation{$R *.dfm}procedure TMyShape.MyPaint(var Msg:TMessage);
    begin
      inherited;
      Canvas.TextOut(5,5,Str);
    end;procedure TForm1.FormCreate(Sender: TObject);
    begin
      MyShape:=TMyShape.Create(Self);
      with MyShape do
      begin
        Parent:=self;
        top:=10;
        left:=10;
        Width:=100;
        Height:=50;
        Str:='Test';  //你要显示的文字
      end;
    end;procedure TForm1.FormDestroy(Sender: TObject);
    begin
      MyShape.Free;
    end;