線上訂房服務-台灣趴趴狗聯合訂房中心
發文 回覆 瀏覽次數:2085
推到 Plurk!
推到 Facebook!

如何自動排序視窗被最大化或拖拉時視窗內元件位置??

尚未結案
clio4177
一般會員


發表:28
回覆:21
積分:9
註冊:2002-07-17

發送簡訊給我
#1 引用回覆 回覆 發表時間:2003-05-24 18:31:37 IP:163.28.xxx.xxx 未訂閱
各位大大: 請問一般在Form中所擺置的可視化元件,如果Form被最大化或視窗調整,這些元件就會偏擺在Form的某個位置而不會自動的調整位置,類似此種自動調整元件可視化元件位置程式該如何撰寫?可否給我一點意見或範例作說明,謝謝各位大大!!
taishyang
站務副站長


發表:377
回覆:5490
積分:4563
註冊:2002-10-08

發送簡訊給我
#2 引用回覆 回覆 發表時間:2003-05-24 18:38:18 IP:140.135.xxx.xxx 未訂閱
clio4177您好:   您的意思指的是可以讓Form中的元件跟隨Form放大自動調整相對位置嗎?   那您可以參考dllee大哥的作品[如何讓Form中的元件跟隨Form放大自動調整相對位置]   http://delphi.ktop.com.tw/topic.php?TOPIC_ID=29206 順心 <>~我也是在學習的階段,所以請您多多見諒與指教~
turboted
版主


發表:95
回覆:754
積分:452
註冊:2002-07-23

發送簡訊給我
#3 引用回覆 回覆 發表時間:2003-05-24 18:42:14 IP:218.166.xxx.xxx 未訂閱
元件的位置,通常是要您自已去安排的 你可以先把元件基本的位置排好 然後開始算 例如,我在最左方放了一個TreeView.,我希望這個TreeView的寬度是 整個程式畫面的1/4 這樣,在Form OnResize時 您就要把TreeView->Width = Form->Width *1/4; 這是一個很麻煩的動作..
clio4177
一般會員


發表:28
回覆:21
積分:9
註冊:2002-07-17

發送簡訊給我
#4 引用回覆 回覆 發表時間:2003-05-24 21:24:18 IP:163.28.xxx.xxx 未訂閱
To taishyang: 謝謝taishyang與turboted的解說。但若是要將Form中的元件與Form的大小成比列放大或縮小該如何作?小弟有找到一篇用Delphi寫的程式,但由於小弟對Delphi程式不是粉熟,而且有些指令在BCB中的用法又不盡相同,所以將該程式碼列在下面,煩請各位幫小弟轉譯一下: ****Unit1.pas**** unit VSize; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, ExtCtrls, StdCtrls,TypInfo, ComCtrls; type TForm1 = class(TForm) Button1: TButton; Memo1: TMemo; Edit1: TEdit; Label1: TLabel; RadioButton1: TRadioButton; Panel1: TPanel; StatusBar1: TStatusBar; procedure FormCreate(Sender: TObject); procedure FormResize(Sender: TObject); private { Private declarations } OW,OH,OP: Longint; aName: array of String; aLeft,aTop,aWidth,aHeight,aFWidth,aFHeight: array of Longint; public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} procedure TForm1.FormCreate(Sender: TObject); var V: Variant; // I,J: Integer; begin OW := TForm(Sender).Width; OH := TForm(Sender).Height; OP := TForm(Sender).PixelsPerInch; J := 0; // 記錄屬於 TControl 的元件總數 for I := 0 to ComponentCount-1 do if (Components[I] is TControl) then Inc(J); if J > 0 then begin SetLength(aName,J); SetLength(aLeft,J); SetLength(aTop,J); SetLength(aWidth,J); SetLength(aHeight,J); SetLength(aFWidth,J); SetLength(aFHeight,J); for I := Low(aName) to High(aName) do begin aName[I] := ''; aLeft[I] := 0; aTop[I] := 0; aWidth[I] := 0; aHeight[I] := 0; aFWidth[I] := 0; aFHeight[I] := 0; end; end; J := -1; for I := 0 to ComponentCount-1 do begin if not (Components[I] is TControl) then Continue; Inc(J); aName[J] := TControl(Components[I]).Name; aLeft[J] := TControl(Components[I]).Left; aTop[J] := TControl(Components[I]).Top; aWidth[J] := TControl(Components[I]).Width; aHeight[J] := TControl(Components[I]).Height; // 檢查是否有 font property V := GetPropValue (Components[I], 'Font'); if not VarIsNull(V) then begin aFWidth[J] := TEdit(Components[I]).Font.Size; aFHeight[J] := TEdit(Components[I]).Font.Height; end; end; end; procedure TForm1.FormResize(Sender: TObject); var V: Variant; I,J: Integer; L,W,H,T,FS,FH: Longint; NW,NH,NP: Longint; begin // TStatusBar 的 Panel 要特別處理 NW := TForm(Sender).Width; NH := TForm(Sender).Height; NP := TForm(Sender).PixelsPerInch; J := -1; for I := 0 to ComponentCount-1 do begin if not (Components[I] is TControl) then Continue; Inc(J); L := aLeft[J]; W := aWidth[J]; H := aHeight[J]; T := aTop[J]; if OW <> 0 then TControl(Components[I]).Left := Longint(L*NW div OW); if OH <> 0 then TControl(Components[I]).Top := Longint(T*NH div OH); if OW <> 0 then TControl(Components[I]).Width := Longint(W*NW div OW); if OH <> 0 then TControl(Components[I]).Height := Longint(H*NH div OH); // 檢查是否有 font property V := GetPropValue (Components[I], 'Font'); if not VarIsNull(V) then begin FS := aFWidth[J]; FH := aFHeight[J]; if (OP <> 0) and (OW <> 0) then begin TEdit(Components[I]).Font.Size := Longint((FS * NP div OP) * NW div OW); TEdit(Components[I]).Font.Height := Longint((FH * NP div OP) * NH div OH); end; end; end; end; end.
taishyang
站務副站長


發表:377
回覆:5490
積分:4563
註冊:2002-10-08

發送簡訊給我
#5 引用回覆 回覆 發表時間:2003-05-24 21:33:47 IP:140.135.xxx.xxx 未訂閱
clio4177您好:    
引言: 但若是要將Form中的元件與Form的大小成比列放大或縮小該如何作?
我也不懂Delphi, 不過您可以再參考這篇連結文章 http://delphi.ktop.com.tw/topic.php?topic_id=26525 順心 <>~我也是在學習的階段,所以請您多多見諒與指教~ 發表人 -
turboted
版主


發表:95
回覆:754
積分:452
註冊:2002-07-23

發送簡訊給我
#6 引用回覆 回覆 發表時間:2003-05-24 22:03:56 IP:218.166.xxx.xxx 未訂閱
請您說出,問題的所在 不會要網友幫您轉整篇的文章吧
clio4177
一般會員


發表:28
回覆:21
積分:9
註冊:2002-07-17

發送簡訊給我
#7 引用回覆 回覆 發表時間:2003-05-25 09:28:08 IP:163.28.xxx.xxx 未訂閱
各位大大: 不好意思沒把要問的問題說清楚。關於Post上去的程式問題如下: 1.//如何對應到BCB語法的變數宣告 aName: array of String; aLeft,aTop,aWidth,aHeight,aFWidth,aFHeight: array of Longint; V: Variant; 2.上述第三行中的Variant在BCB中是指啥意思? 3.關於判斷式及迴圈的問題 ***Type A*** for I := 0 to ComponentCount-1 do if (Components[I] is TControl) then Inc(J); : : end end : *** Type B*** for I := 0 to ComponentCount-1 do begin if not (Components[I] is TControl) then Continue; : : end end Delphi的判斷式及迴圈中,為何沒有加入邏輯運算符號?其次,迴圈中也未見到迴圈變數的遞增或遞減參數宣告?如Type A及B中迴圈I由0開始到ComponentCount-1,其遞增或遞減參數是宣告在何處?另外,if的判斷是中 not (Components[I] is TControl) 又是表現何種意義?Inc(J)又是代表啥意思?可否請各位大大就上述的幾個問題幫小弟解說一下該如將這些程式語法轉譯成BCB的參數宣告及判斷式或迴圈的語法?謝謝各位大大!!
turboted
版主


發表:95
回覆:754
積分:452
註冊:2002-07-23

發送簡訊給我
#8 引用回覆 回覆 發表時間:2003-05-25 10:38:19 IP:218.166.xxx.xxx 未訂閱
aName: array of String; String aName[要有size]; 以上array宣告同上原理 Variant就是一種type 打入Variant自已看help吧 if (Components[I] is TControl) 是判斷找到的Components[i]是不是TControl Inc(J); J 的意思
clio4177
一般會員


發表:28
回覆:21
積分:9
註冊:2002-07-17

發送簡訊給我
#9 引用回覆 回覆 發表時間:2003-05-25 11:20:38 IP:163.28.xxx.xxx 未訂閱
To turboted: 引言************************************* if (Components[I] is TControl) 是判斷找到的Components[i]是不是TControl ***************************************** 在BCB是不是宣告成如此 if (Compinents[I] == TControl) 如果不是的話可否請您指證! Delphi中宣告Variant是要表達什麼意思??
turboted
版主


發表:95
回覆:754
積分:452
註冊:2002-07-23

發送簡訊給我
#10 引用回覆 回覆 發表時間:2003-05-25 11:38:34 IP:218.166.xxx.xxx 未訂閱
variant 可動態改變其資料型態 v:variant; v := 1; v:= 123.34; Sometimes it is necessary to manipulate data whose type varies or cannot be determined at compile time. In these cases, one option is to use variables and parameters of type Variant, which represent values that can change type at runtime. Variants, as they are called, offer greater flexibility but consume more memory than regular variables, and operations on them are slower than on statically bound types. Moreover, illicit operations on variants often result in runtime errors, where similar mistakes with regular variables would have been caught at compile time. Variants can hold values of any type except records, sets, static arrays, files, classes, class references, pointers, and Int64. In other words, with the exception of Int64, variants can hold anything but structured types and pointers. They can hold COM and CORBA objects, whose methods and properties can be accessed through them. (See Object interfaces.) They can hold dynamic arrays, and they can hold a special kind of static array called a variant array. (See Variant arrays.) Variants can mix with other variants and with integer, real, string, and Boolean values in expressions and assignments; the compiler automatically performs type conversions. Variants that contain strings cannot be indexed. That is, if V is a variant that holds a string value, the construction V[1] is illegitimate. A variant occupies 16 bytes of memory and consists of a type code and a value, or pointer to a value, of the type specified by the code. All variants are initialized on creation to the special value Unassigned. The special value Null indicates unknown or missing data. The standard function VarType returns a variants type code. The varTypeMask constant is a bit mask used to extract the code from VarTypes return value, so that, for example, VarType(V) and varTypeMask = varDouble returns True if V contains a Double or an array of Double. (The mask simply hides the first bit, which indicates whether the variant holds an array.) The TVarData record type defined in the System unit can be used to typecast variants and gain access to their internal representation. See the online Help on VarType for a list if codes, and note that new type codes may be added in future implementations of Object Pascal.
clio4177
一般會員


發表:28
回覆:21
積分:9
註冊:2002-07-17

發送簡訊給我
#11 引用回覆 回覆 發表時間:2003-05-25 16:23:18 IP:163.28.xxx.xxx 未訂閱
各位大大: 關於上文中的程式部分,還是不太清楚該如何轉譯成BCB程式碼。問題如下: 1.SetLength(aName,J); 2.for I := Low(aName) to High(aName) do begin : end 3.for I := 0 to ComponentCount-1 do begin : end 請問上述三個問題該如何轉譯?在BCB中Setlength()中只有一個變數而已,在Delphi中卻出現兩個變數請問該如何處置?
taishyang
站務副站長


發表:377
回覆:5490
積分:4563
註冊:2002-10-08

發送簡訊給我
#12 引用回覆 回覆 發表時間:2003-05-25 16:30:46 IP:140.135.xxx.xxx 未訂閱
clio4177您好:   不好意思,我已幫不上忙...   您的問題已經跟原問題不一樣了 [自動調整元件可視化元件位置]--& > <>~我也是在學習的階段,所以請您多多見諒與指教~
turboted
版主


發表:95
回覆:754
積分:452
註冊:2002-07-23

發送簡訊給我
#13 引用回覆 回覆 發表時間:2003-05-25 16:33:47 IP:218.166.xxx.xxx 未訂閱
(1)aName.SetLength(J); (3)for (int i = 0 ; i < ComponentCount -1 ; i ) 要是要問下去,我想,就沒人想要回答了 發表人 - turboted 於 2003/05/25 16:34:46
系統時間:2024-04-29 11:40:42
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!