我想试着在TEdit类控件后面弄个类似于combobox后面跟着的那个小按钮;
并可以选择改变按钮的类型;
怎么能够实现;
我的意思是从TCustomControl开始继承的话;怎么能画出这种效果来;实现后分数一定会加到100的;
麻烦兄弟们帮帮忙

解决方案 »

  1.   


    TAKind = (AKind1,AKind2);
    TAEdit = class(TCustomCombobox)
    private
      FAKind : TAKind;
      procedure SetAKind(Value: TAKind);
    public
      procedure RecreateWnd override;
    published 
      property AKind: TAKind read FAKind write SetAKind ;
    end;implication
    procedure TAEdit.RecreateWnd;
    begin
    ???????????????
    end;应该是重载上面的这个函数来实现吧;
    问题是怎么编写上面的代码?
      

  2.   

    先用Frame做一个样子,然后将Frame翻译成你需要的控件即可,懒省事的话
    可以将作出的Frame放到TCustomControl中,缺点是浪费一个窗口句柄。欢迎访问我的网站,站上的软件都是用Delphi开发的:
    地址: http://lysee.oicp.net
      

  3.   

    楼主的方向有点错, 不能考虑用画的办法
    有两种办法可以实现
    1. 考虑控件组合, 在 additional 页中有一个 LabeledEdit, 那个 label 就是组合在 Edit 上的, label 所要做的就是跟着 Edit 改变位置就可以, 如果是个 Button 的话, 还应把 Button 的事件也作到 Edit 里, 办法也简单, 比方写个新事件 OnButtonClick 在代码中写到 FButton.Click
      

  4.   

    2. 是子类化, 由于 1 的办法要派生出一个新的Edit组件, 产生新的问题, DBEdit 是不是也要这么作, 类似组件是不是都要作一次? 或者可以只写一个Button, 可以关联到任何的 Controls 上?子类化也有两种办法, Windows 子类化和 VCL子类化, 
    Windows子类化就是用SetWindowLong 代替, 原来的处理过程, 这种方法只能在 Windows 平台使用VCL 子类化就是代替VCL 消息处理过程, Control类的WindowProc
    写的个新的 Button 类, TAssociateButton, 新加入个 Associate: TControl; 属性 read, write, 加入一个新的 AssociateMsgProc, 跟 WindowProc 类型相同, 大概代码如下procedure TAssociateButton.AssociateMsgProc(var Message: TMessage);
    begin
      // ... 好像写起来有点烦, 主要是处理, WM_MOVE(CM_MOVE), WM_SIZE(CM_SITE) 消息, 让你的组件关联到位置
    end;新方法 SetSubclassing
    begin
      if Assigned(FControl) then
      begin
        FOldWindowProc := FControl.WindowProc; 记得保存现场, 在组件 destroy或反子类化子还原哈
        FControl.WindowProc := AssociateMsgProc;
      end;
    end;新方法 UnSubclassing
    begin
      if Assigned(FControl) and Assigned(FOldWindowProc) then
        FControl.WindowProc := FOldWindowProc;
    end;重载 Loaded 方法
    begin
      inherited;
      if csDesigning not in ComponentState then
        SetSubclassing;
    end;SetAssociate 方法
    begin
      if Value <> FControl then 
      begin
        if Assigned(FControl) then // 原来有
        begin
          if csDesigning not in ComponentState then
            UnSubclassing;
        end;
        
        FControl := Value;    if csDesigning not in ComponentState then
          SetSubclassing;
    end;
      差不多了, 大概如此, 代码现写的, 没有经过编译, 楼主自已要多玩玩
      

  5.   

    差不多比较完整的代码了, 我没找到怎样在运行期也跟着动楼主自已想想办法了, 还有不能关联自已unit AsoBtn;interfaceuses
      SysUtils, Classes, Controls, StdCtrls, Messages;type
      TAssociateButton = class(TButton)
      private
        FAssociate: TControl;
        FOldWindowProc: TWndMethod;    procedure AdujstBounds;
        procedure AssociateWindowProc(var Message: TMessage);
        procedure SetSubclassing;
        procedure Unsubclassing;
        procedure SetAssociate(const Value: TControl);
      protected
        procedure Loaded; override;
      public
        constructor Create(AOwner: TComponent); override;
        destructor Destroy; override;
      published
        property Associate: TControl read FAssociate write SetAssociate;
      end;procedure Register;implementationprocedure Register;
    begin
      RegisterComponents('Additional', [TAssociateButton]);
    end;{ TAssociateButton }constructor TAssociateButton.Create(AOwner: TComponent);
    begin
      inherited;end;destructor TAssociateButton.Destroy;
    begin
      Unsubclassing;
      inherited;
    end;procedure TAssociateButton.AssociateWindowProc(var Message: TMessage);
    begin
      FOldWindowProc(Message); { inherited }  case Message.WParam of
        WM_MOVE, WM_SIZE:
          AdjustBounds;
      end
    end;procedure TAssociateButton.Loaded;
    begin
      inherited;
      if not (csDesigning in ComponentState) then
      begin
      end;
    end;procedure TAssociateButton.SetAssociate(const Value: TControl);
    begin
      if Value <> FAssociate then
      begin
        Unsubclassing;
        
        FAssociate := Value;
        
        SetSubclassing;
      end;
    end;procedure TAssociateButton.SetSubclassing;
    begin
      if Assigned(FAssociate)then
      begin
        FOldWindowProc := FAssociate.WindowProc;
        FAssociate.WindowProc := AssociateWindowProc;
      end;
    end;procedure TAssociateButton.Unsubclassing;
    begin
      if Assigned(FAssociate) and Assigned(FOldWindowProc) then
        FAssociate.WindowProc := FOldWindowProc;
    end;procedure TAssociateButton.AdujstBounds;
    begin
      Left := FAssociate.Left + FAssociate.Width;
      Top := FAssociate.Top;
      Height := FAssociate.Height;
    end;end.
      

  6.   

    修正几个地方
    派生
      TAssociateButton = class(TSpeedButton)procedure TAssociateButton.SetAssociate(const Value: TControl);
    begin
      if Value = Self then Exit; // 防止是自已
      
      if Value <> FAssociate then
      begin
        Unsubclassing;
        
        FAssociate := Value;
        
        SetSubclassing;
      end;
    end;// 处理消息处
    procedure TAssociateButton.AssociateWindowProc(var Message: TMessage);
    begin
      FOldWindowProc(Message); { inherited }  case Message.WParam of
        WM_WINDOWPOSCHANGED: // 改成这个
          AdjustBounds;
      end
    end;// 加入新方法, 在关联组件被删时
    procedure Notification(AComponent: TComponent; Operation: TOperation); override;procedure TAssociateButton.Notification(AComponent: TComponent;
      Operation: TOperation);
    begin
      inherited Notification(AComponent, Operation);
      if (Operation = opRemove) and (AComponent = FAssociate) then
        Unsubclassing;
    end;目还是找不到方法在设计期跟着动
      

  7.   

    comanche(太可怕) 
    谢谢哥们;记住你了;^_^;以后有事就都找你了;^_^
    我会去试的;马上揭帖;^_^