TMyEdit = class(TCustomEdit)
  protected
    procedure MouseMove(Shift: TShiftState; X, Y: Integer);这样不会失效,当创建一个按钮在上面时,为什么失效了?  TMyEdit = class(TCustomEdit)
  private
    FBtn: TButton;
  protected
    procedure MouseMove(Shift: TShiftState; X, Y: Integer);
  public
    constructor Create(AOwner: TComponent); override;
  end;
constructor TTractBarEdit.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  ControlStyle := ControlStyle - [csAcceptsControls, csSetCaption] + [csOpaque];
  if not NewStyleControls then ControlStyle := ControlStyle + [csFramed];
  Height := 21;
  width := 60;
    FBtn := TButton.Create(Self);
    FBtn.Visible := True;
    FBtn.Parent := Self;
    FBtn.SetBounds(0, 0, Height-8, Height-8);
end;

解决方案 »

  1.   

    constructor TTractBarEdit.Create(AOwner: TComponent);
    //////////怎么回事?TTractBarEdit还是TMyEdit???
    另外你写MouseMove(Shift: TShiftState; X, Y: Integer);有什么打算?难道你要做一个OnMouseMove的东西出来?而且你为什么写在protected里面那?
    对楼主的类的构造十分不解!!!
      

  2.   

    TTractBarEdit写错了  是TMyEditMouseMove(Shift: TShiftState; X, Y: Integer); 不该写在protected里吗?如果我不在上面加按钮的话就有效,加了就无效了?
      

  3.   

    你是在Create里面用了这句话吗?
    self.OnMouseMove:=MouseMove;
    //////然后添加了Fbtn之后就不执行MouseMove了?MouseMove(Shift: TShiftState; X, Y: Integer); 不该写在protected里吗?
    ////////不是不该,如果不显式的调用的话,放在private里面就可以了,protected里面一般都是为了子类继承用的...
      

  4.   

    你是在Create里面用了这句话吗?
    self.OnMouseMove:=MouseMove;没用这句代码?  但是我搞不懂,当添加了一个按钮MouseMove就失效了??真不知道为什么?
      

  5.   

    晕,查到问题了,原来我起先加了消息,截获了mousemove,
      protected
        procedure wndproc(var message:Tmessage);override;procedure TMyEdit.wndproc(var message: Tmessage);
    begin
    if FBTn<>nil then
     if (message.msg=wm_mousemove) then
       if (message.LParamLo >= width-fbtn.Width-4) then
     begin
      cursor:=crarrow;
      exit;
     end else
     begin
      cursor:=crDefault;
      exit;
     end;
     inherited wndproc(message);
    end;改变光标本来想在edit上画个按钮的,怎么也搞不定
      

  6.   

    晕啊~~~~
    往Edit上画按钮好像只是设置按钮的parent是搞不定的……