如何製作可以有Autosize寬度的Edit元件呢? |
尚未結案
|
SKYSTAR
中階會員 發表:76 回覆:198 積分:64 註冊:2002-06-10 發送簡訊給我 |
|
cmf
尊榮會員 發表:84 回覆:918 積分:1032 註冊:2002-06-26 發送簡訊給我 |
|
SKYSTAR
中階會員 發表:76 回覆:198 積分:64 註冊:2002-06-10 發送簡訊給我 |
To: cmf.... 我的問題已解決了.... 不過還是謝謝您的關心.... 我原本是想利用 > 我把原始碼列在下面....供有想要參考的朋友來看看....
另外...再向您說聲謝謝囉!!
< class="code">
unit SKYEditAutoSize; interface uses
Windows, Messages, SysUtils, Classes, Controls, Forms, StdCtrls, ExtCtrls, Graphics; type
TSKYEditAutoSize = class(TComponent)
private
FAutoSize: Boolean;
procedure SetAutoSize(Value: Boolean);
procedure RunAutoSize;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
published
property AutoSize: Boolean read FAutoSize write SetAutoSize default False;
end; procedure Register; implementation uses DBCtrls; procedure Register;
begin
RegisterComponents('SKYSTAR', [TSKYEditAutoSize]);
end; constructor TSKYEditAutoSize.Create(AOwner: TComponent);
begin
inherited;
FAutoSize := False;
end; destructor TSKYEditAutoSize.Destroy;
begin
inherited;
end; procedure TSKYEditAutoSize.RunAutoSize;
// [程序]:調整元件自動長寬的大小
// [傳入]:
var
V_Label: TLabel;
V_Loop: integer;
begin
// ....建立一個Label元件,參考其寬度值
V_Label := TLabel.Create(nil);
V_Label.AutoSize := True;
// ....
for V_Loop := 0 to Owner.ComponentCount-1 do
begin
if Owner.Components[V_Loop].Tag = -1 then // 元件的Tag設成-1時,表示要調整大小
begin
if Owner.Components[V_Loop].ClassType = TEdit then
begin
V_Label.Font := TEdit(Owner.Components[V_Loop]).Font;
V_Label.Caption := TEdit(Owner.Components[V_Loop]).Text;
// ....依據元件的內容值及樣式,設定其寬度
TEdit(Owner.Components[V_Loop]).Width := V_Label.Width 2; // 必須先加上2
if TEdit(Owner.Components[V_Loop]).BorderStyle = bsSingle then
TEdit(Owner.Components[V_Loop]).Width := TEdit(Owner.Components[V_Loop]).Width 4;
if TEdit(Owner.Components[V_Loop]).BevelKind <> bkNone then
TEdit(Owner.Components[V_Loop]).Width := TEdit(Owner.Components[V_Loop]).Width 4;
// ....
// ....重新啟動AutoSize,設定其高度
TEdit(Owner.Components[V_Loop]).AutoSize := False;
TEdit(Owner.Components[V_Loop]).AutoSize := True;
// ....
end;
if Owner.Components[V_Loop].ClassType = TDBEdit then
begin
V_Label.Font := TDBEdit(Owner.Components[V_Loop]).Font;
V_Label.Caption := TDBEdit(Owner.Components[V_Loop]).Text;
TDBEdit(Owner.Components[V_Loop]).Width := V_Label.Width 2;
if TDBEdit(Owner.Components[V_Loop]).BorderStyle = bsSingle then
TDBEdit(Owner.Components[V_Loop]).Width := TDBEdit(Owner.Components[V_Loop]).Width 4;
if TDBEdit(Owner.Components[V_Loop]).BevelKind <> bkNone then
TDBEdit(Owner.Components[V_Loop]).Width := TDBEdit(Owner.Components[V_Loop]).Width 4;
TDBEdit(Owner.Components[V_Loop]).AutoSize := False;
TDBEdit(Owner.Components[V_Loop]).AutoSize := True;
end;
Owner.Components[V_Loop].Tag := 0; // 將調整完成之元件的Tag設成0
end;
end;
FreeAndNil(V_Label);
end; procedure TSKYEditAutoSize.SetAutoSize(Value: Boolean);
begin
if FAutoSize <> Value then
begin
FAutoSize := Value;
if Value then
RunAutoSize;
end;
end; end.
|
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |