你的 Label 的 AutoSize 是不是 true ?

解决方案 »

  1.   

    zengyufeng :
       与label毫无关系!
      

  2.   

    1)从TWinControl继承下来,不要从TGraphicControl继承。
    2)调整位置在Paint中?,太奇怪了,要么重载SetBounds,要么处理WM_SIZE
    3)Onclik处理的不好,你这样也可以吗?
    4);    fbutton.parent:=twincontrol(aowner);
        flabel:=tlabel.create(self);
        flabel.parent:=twincontrol(aowner);
        fbutton.width:=10;
        fbutton.height:=10;
        fbutton.top:=top;
        fbutton.left:=Left;
        flabel.caption:='newcom';
        flabel.width:=100;
        flabel.height:=20;
        flabel.left:=left-10;
        flabel.top:=top+20;
        flabel.Transparent:=true;
       位置的调整有很多错误。left,top的含义理解的不对。
      

  3.   

    kxy:
       现在要求做的东西是全部是透明的,所以twincontrol是不行的!
       因为TGraphicControl没有焦点,你在Create设置它的位置是没用的,
       Onclick我测试没问题啊!
      

  4.   

    zxy:
      你现在用Wincontrol当然会认为我的left不对;
      但用TGraphicControl,你安装一下我写的,你会发现位置没错
      毕竟TGraphicControl是没焦点的!
      

  5.   

    因为TGraphicControl与TWinControl不同,他没有自己的HWND,照说是不能在其上建立子控件的.
    对于TWinControl要做成透明的效果,可以取得父窗口的dc,然后把父窗口的图像绘制出来.
      

  6.   

    //这是我改写的控件,拿去用
    unit SButton;interfaceuses
      Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, Buttons, StdCtrls,
      Math;type
      TSButton = class(TWinControl)
      private
        FButton: TSpeedButton;
        FLabel: TLabel;
      protected
        procedure Resize; override;
      public
        constructor Create(AOwner: TComponent); override;
        destructor Destroy; override;
      end;procedure Register;implementationprocedure Register;
    begin
      RegisterComponents('OwnComponents', [TSButton]);
    end;{ TSButton }constructor TSButton.Create(AOwner: TComponent);
    begin
      inherited Create(AOwner);
      Parent := TWinControl(AOwner);  FButton := TSpeedButton.Create(Self);
      FLabel := TLabel.Create(Self);
      with FButton do
      begin
        Parent := Self;
        Flat := true;
        Top := 0;
        Width := 10;
        Height := 10;
      end;
      with FLabel do
      begin
        Parent := Self;
        Caption := 'abcdefg';
        Top := FButton.Top + FButton.Height + 2;
      end;
      Width := Max(FButton.Width, FLabel.Width);
      Height := FButton.Height + FLabel.Height + 2;
    end;destructor TSButton.Destroy;
    begin
      FButton.Free;
      FLabel.Free;
      inherited Destroy;
    end;procedure TSButton.Resize;
    begin
      inherited Resize;
      if Assigned(FButton) and Assigned(FLabel) then
      begin
        FButton.Left := (Width - FButton.Width) div 2;
        FLabel.Left := (Width - FLabel.Width) div 2;
        Height := FButton.Height + FLabel.Height + 2;
      end;
    end;end.
      

  7.   

    cybercake说得对,主要问题是自己写会忒麻烦,会不稳定!
    zengyufeng:是TGraphicControl
    kxy:怎么没回音了??