元件內的元件大小會不一樣 |
答題得分者是:andersonhsieh
|
skurama
中階會員 發表:88 回覆:127 積分:73 註冊:2002-07-22 發送簡訊給我 |
請問:
我在Panel1上加了一個Label1
當我在DesignTime時設定Panel1時,我有程式會設定Label跟著改變 可是當我存檔後,關閉程式在打開時,
我的Panel1大小不變,但是我的Label1會變回預設的大小
以下是我的程式碼 unit YNPLabel; interface uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ExtCtrls, stdctrls; type
TYNPLabel = class(TPanel)
private
//要放在Panel上的Label
Label1 : TLabel;
{ Private declarations }
protected
procedure NewReSize(Sender: TObject);
//設定和取得Label的caption
procedure Set_Label1(const Value: String);
function Get_Label1: String;
{ Protected declarations }
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
{ Public declarations }
published
//設定Label的Name
property YN_Caption : String read Get_Label1 write Set_Label1;
{ Published declarations }
end; procedure Register; implementation procedure Register;
begin
RegisterComponents('YoungNet VCL V2', [TYNPLabel]);
end; { TYNPLabel } constructor TYNPLabel.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
Label1 := TLabel.create(self);
Label1.parent := self;
Label1.AutoSize := false;
Label1.Alignment := taCenter;
Label1.Layout := tlCenter;
Label1.Cursor := crHandPoint;
Label1.Caption := 'YNPLabel';
Label1.AutoSize := false;
self.OnResize := NewReSize; //設定元件大小
if csDesigning in ComponentState then begin
Self.width := 50;
Self.height := 18;
Label1.Left := 0;
Label1.Top := 0;
NewReSize(self);
end;
end; destructor TYNPLabel.Destroy;
begin
inherited Destroy;
end; function TYNPLabel.Get_Label1: String;
begin
Result := Label1.caption;
end; procedure TYNPLabel.NewReSize(Sender: TObject);
begin
Label1.Width := self.width;
Label1.Height := self.height;
end; procedure TYNPLabel.Set_Label1(const Value: String);
begin
Label1.caption := Value;
end; end. 請問我須要再哪個Event下更改Label的大小
------
---------------- 初出芧房程設師, 左鍵右鼠寫程式, 日扣夜寫眼框溼, 望能早成系分師。 ---------------- |
hagar
版主 發表:143 回覆:4056 積分:4445 註冊:2002-04-14 發送簡訊給我 |
|
skurama
中階會員 發表:88 回覆:127 積分:73 註冊:2002-07-22 發送簡訊給我 |
|
andersonhsieh
版主 發表:33 回覆:531 積分:439 註冊:2002-06-10 發送簡訊給我 |
引言: 請問: 我在Panel1上加了一個Label1 當我在DesignTime時設定Panel1時,我有程式會設定Label跟著改變 可是當我存檔後,關閉程式在打開時, 我的Panel1大小不變,但是我的Label1會變回預設的大小 以下是我的程式碼 unit YNPLabel; interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, ExtCtrls, stdctrls; type TYNPLabel = class(TPanel) private //要放在Panel上的Label Label1 : TLabel; { Private declarations } procedure WMSIZING(var msg : TMessage); message WM_SIZING;加入這一行 protected procedure NewReSize(Sender: TObject);不用 //設定和取得Label的caption procedure Set_Label1(const Value: String); function Get_Label1: String; { Protected declarations } public constructor Create(AOwner: TComponent); override; destructor Destroy; override; { Public declarations } published //設定Label的Name property YN_Caption : String read Get_Label1 write Set_Label1; { Published declarations } end; procedure Register; implementation procedure Register; begin RegisterComponents('YoungNet VCL V2', [TYNPLabel]); end; { TYNPLabel } constructor TYNPLabel.Create(AOwner: TComponent); begin inherited Create(AOwner); Label1 := TLabel.create(self); Label1.parent := self; Label1.AutoSize := false; Label1.Alignment := taCenter; Label1.Layout := tlCenter; Label1.Cursor := crHandPoint; Label1.Caption := 'YNPLabel'; Label1.AutoSize := false; self.OnResize := NewReSize;建議不要這樣做要直接攔截MESSAGE比較正確 這裡不須要 //設定元件大小 if csDesigning in ComponentState then begin Self.width := 50; Self.height := 18; Label1.Left := 0; Label1.Top := 0; NewReSize(self); end; end; destructor TYNPLabel.Destroy; begin inherited Destroy; end; function TYNPLabel.Get_Label1: String; begin Result := Label1.caption; end; procedure TYNPLabel.NewReSize(Sender: TObject); begin Label1.Width := self.width; Label1.Height := self.height; end; procedure TYNPLabel.Set_Label1(const Value: String); begin Label1.caption := Value; end; end. 新增 procedure TYNPLabel.WMSIZING(var msg : TMessage); begin Label1.Width := width; Label1.Height := height; end; 請問我須要再哪個Event下更改Label的大小@@~~飛翔在天際的精靈~~@@
------
@@~~飛翔在天際的精靈~~@@ |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |