【发布时间】:2011-05-14 04:09:20
【问题描述】:
我有一个来自 TGraphicControl 的自定义 Delphi 组件。它的类声明如下:
TMyLabel = class(TGraphicControl)
private
...
protected
...
public
...
published
property Height;
property Width write SetWidth;
...
end;
SetWidth 的实现更进一步:
procedure TMyLabel.SetWidth(const Value: Integer);
begin
if (Value >= 0) and (Value <> Width)
then begin
inherited Width := Value;
// Do some other stuff
...
end;
MessageDlg('Test', mtInformation, [mbOK], 0);
end;
当前,当组件的宽度在运行时或设计时通过在对象检查器的相应字段中输入值以编程方式更改时,我会调用 SetWidth。但是,当我在设计时使用鼠标调整组件大小时,对象检查器的“宽度”字段会更新,但没有显示消息框,因此不会调用我的 SetWidth 过程。
我需要在鼠标调整组件大小时调用 SetWidth,以便我可以为 Paint 过程设置一个标志,以了解它何时必须执行其他操作(除了重绘组件之外)。有没有办法做到这一点?
【问题讨论】:
-
+1,因为它带来了 3 个很好且互补的答案。当然,它本身也有优点,如果只是为了避免错误;-)
标签: delphi properties components