全國最多中醫師線上諮詢網站-台灣中醫網
發文 回覆 瀏覽次數:1260
推到 Plurk!
推到 Facebook!

如何製作可以有Autosize寬度的Edit元件呢?

尚未結案
SKYSTAR
中階會員


發表:76
回覆:198
積分:64
註冊:2002-06-10

發送簡訊給我
#1 引用回覆 回覆 發表時間:2003-02-28 06:35:56 IP:218.187.xxx.xxx 未訂閱
煩請教各位大大.... 如何才可以使Edit和Label一樣...做到寬度的Autosize呢? 因為目前Edit的Autosize只能做到高度的部份....?? 我查過Source Code...也試著將Label的SetAutosize()全部照抄到我所要新建 的MyEdit中...可是會出現錯誤..... 我想應該是Edit和Label的類別不同吧! 請問我該如何做,才可以用Edit為基礎...但是可以擁有Label的Autosize呢? Thanks!!
cmf
尊榮會員


發表:84
回覆:918
積分:1032
註冊:2002-06-26

發送簡訊給我
#2 引用回覆 回覆 發表時間:2003-02-28 09:35:44 IP:61.218.xxx.xxx 未訂閱
SKYSTAR:    請問    MyEdit.SetAutosize() 所產生的錯誤訊息是什麼?    可否將 MyEdit.SetAutosize() 內容貼上來?    僅供參考,歡迎繼續發言
------
︿︿
SKYSTAR
中階會員


發表:76
回覆:198
積分:64
註冊:2002-06-10

發送簡訊給我
#3 引用回覆 回覆 發表時間:2003-03-03 01:10:24 IP:218.187.xxx.xxx 未訂閱
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.
系統時間:2024-05-04 20:57:14
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!