代码之家  ›  专栏  ›  技术社区  ›  Ian Boyd

德尔菲:怎么知道泰迪熊什么时候会变大?

  •  3
  • Ian Boyd  · 技术社区  · 15 年前

    当编辑框改变大小时,我需要更新它周围的项目。

    TEdit没有 改变大小时 事件。

    编辑框可以随时调整大小,例如:

    • 更改代码中的宽度/高度
    • DPI缩放的窗体
    • 字体更改

    我相信我不认识的人。

    我需要一个事件来知道编辑框的大小何时改变。是否有Windows消息可以为其子类化编辑框并获取?

    3 回复  |  直到 15 年前
        1
  •  9
  •   Bruce McGee    15 年前

    OnResize声明为Tcontrol的受保护属性。您可以使用所谓的“cracker”类公开它。不过,这有点像黑客。

    type
      TControlCracker = class(TControl);
    

    procedure TForm1.FormCreate(Sender: TObject);
    begin
      TControlCracker(Edit1).OnResize := MyEditResize;
    end;
    
    procedure TForm1.MyEditResize(Sender: TObject);
    begin
      Memo1.Lines.Add(IntToStr(Edit1.Width));
    end;
    
        2
  •  3
  •   Jeroen Wiert Pluimers    15 年前

    您是否尝试过类似的操作:

    unit _MM_Copy_Buffer_;
    
    interface
    
    type
      TMyEdit = class(TCustomEdit)
      protected
        procedure Resize; override;
      end;
    
    implementation
    
    procedure TMyEdit.Resize;
    begin
      inherited;
      if not (csLoading in ComponentState) then
      begin
        // react on new size
      end;
    end;
    
    end.
    

    或者:

    unit _MM_Copy_Buffer_;
    
    interface
    
    type
      TCustomComboEdit = class(TCustomMaskEdit)
      private
        procedure WMSize(var Message: TWMSize); message WM_SIZE;
      end;
    
    implementation
    
    procedure TCustomComboEdit.WMSize(var Message: TWMSize);
    begin
      inherited;
      if not (csLoading in ComponentState) then
      begin
        // react on new size
      end;
      UpdateBtnBounds;
    end;
    
    end.
    
        3
  •  1
  •   Rob Kennedy    15 年前

    处理 wm_Size 消息。通过将新值赋给控件的子类 WindowProc 属性;请确保存储旧值,以便可以在那里委托其他消息。

    另请参见: wm_WindowPosChanged