關於元件中用Message攔截事件 |
答題得分者是:william
|
skurama
中階會員 發表:88 回覆:127 積分:73 註冊:2002-07-22 發送簡訊給我 |
請問:
目前我想寫一個元件,繼承Panel後,
上面有一張背景圖,當Panel改變大小時,
圖片會更著改變大小。 在http://delphi.ktop.com.tw/topic.php?TOPIC_ID=21296
此篇中 andersonhsieh 大大有說到不要直接取代 panel的resize事件。 於是我照該篇改成以下 unit YNToolBar; interface uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ExtCtrls, YNImage, stdctrls; type
TTLb = class(TPanel)
private
POwner: TComponent;
procedure WMSIZING(var msg : TMessage); message WM_SIZING;
protected
{********* 基本元件宣告 *********}
Label1 : TLabel;
{ Protected declarations }
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
{ Public declarations }
published
{ Published declarations }
end; procedure Register; implementation {$R *.res} procedure Register;
begin
RegisterComponents('TEST Component', [TTLb]);
end; { TYNToolBar } constructor TTLb.Create(AOwner: TComponent);
begin
inherited Create(AOwner); //讓PWoner指向元件的擁有者(父元件)
POwner := Owner;
self.parent := AOwner as TWinControl; //設定Panel的屬性
self.Caption := ''; //------------------圖片建立開始------------------
//背景圖
Label1 := TLabel.Create(self);
Label1.Parent := self;
Label1.caption := 'TEST LABEL1';
end; destructor TTLb.Destroy;
begin
Label1.Free;
inherited Destroy;
end; procedure TTLb.WMSIZING(var msg: TMessage);
begin
Label1.Width := self.Width;
Label1.Height := self.Height;
end; end. 可是WMSIZING 並沒有被觸發,
也就是說,當我的Panel改變大小時,Label並沒有改變。 再問,是否也能攔截到label1的onclick事件,
因為我想要在當Label1被點到時,做某些事情,
還是說元件中的元件就直接用 label1.onclick = new_onclick(); 謝謝~ ----------------
初出芧房程設師,
左鍵右鼠寫程式,
日扣夜寫眼框溼,
望能早成系分師。
----------------
------
---------------- 初出芧房程設師, 左鍵右鼠寫程式, 日扣夜寫眼框溼, 望能早成系分師。 ---------------- |
william
版主 發表:66 回覆:2535 積分:3048 註冊:2002-07-11 發送簡訊給我 |
我想 WM_SIZE 應該比較適合吧。 TControl 有一個 Resize 的 protected method ,要試一下嗎 , class="code">TTLb = class(TPanel)
protected
procedure Resize; override;
end; procedure TTLb.Resize;
begin
if Assigned(Label1) do begin
Label1.Width := self.Width;
Label1.Height := self.Height;
end;
inherited;
end; 除非你打算 publish Label1 ,還是直接用它的 event 吧, i.e. label1.onclick := new_onclick;
|
skurama
中階會員 發表:88 回覆:127 積分:73 註冊:2002-07-22 發送簡訊給我 |
嗯~~
我把
procedure WMSIZING(var msg : TMessage); message WM_SIZING;
改成procedure WMSIZING(var msg : TMessage); message WM_SIZE; 以及程式改成
procedure TTLb.WMSIZING(var msg: TMessage);
begin
if assigned(Label1) then begin
Label1.Width := self.Width;
Label1.Height := self.Height;
end;
end; 謝謝~~ ----------------
初出芧房程設師,
左鍵右鼠寫程式,
日扣夜寫眼框溼,
望能早成系分師。
----------------
------
---------------- 初出芧房程設師, 左鍵右鼠寫程式, 日扣夜寫眼框溼, 望能早成系分師。 ---------------- |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |