我有一個自TGraphicControl降序的自定義Delphi組件。它的類被聲明如下:自定義Delphi組件的Redeclare Width屬性
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個很好的補充答案。當然它有自己的優點,如果只是爲了避免錯誤;-) – 2010-11-23 20:11:33