如何自動排序視窗被最大化或拖拉時視窗內元件位置?? |
尚未結案
|
clio4177
一般會員 發表:28 回覆:21 積分:9 註冊:2002-07-17 發送簡訊給我 |
|
taishyang
站務副站長 發表:377 回覆:5490 積分:4563 註冊:2002-10-08 發送簡訊給我 |
clio4177您好:
您的意思指的是可以讓Form中的元件跟隨Form放大自動調整相對位置嗎?
那您可以參考dllee大哥的作品[如何讓Form中的元件跟隨Form放大自動調整相對位置]
http://delphi.ktop.com.tw/topic.php?TOPIC_ID=29206 順心 <>~我也是在學習的階段,所以請您多多見諒與指教~>
|
turboted
版主 發表:95 回覆:754 積分:452 註冊:2002-07-23 發送簡訊給我 |
|
clio4177
一般會員 發表:28 回覆:21 積分:9 註冊:2002-07-17 發送簡訊給我 |
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 發送簡訊給我 |
clio4177您好:
引言: 但若是要將Form中的元件與Form的大小成比列放大或縮小該如何作?我也不懂Delphi, 不過您可以再參考這篇連結文章 http://delphi.ktop.com.tw/topic.php?topic_id=26525 順心 <>~我也是在學習的階段,所以請您多多見諒與指教~> 發表人 - |
turboted
版主 發表:95 回覆:754 積分:452 註冊:2002-07-23 發送簡訊給我 |
|
clio4177
一般會員 發表:28 回覆:21 積分:9 註冊:2002-07-17 發送簡訊給我 |
各位大大:
不好意思沒把要問的問題說清楚。關於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 發送簡訊給我 |
|
clio4177
一般會員 發表:28 回覆:21 積分:9 註冊:2002-07-17 發送簡訊給我 |
|
turboted
版主 發表:95 回覆:754 積分:452 註冊:2002-07-23 發送簡訊給我 |
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 發送簡訊給我 |
|
taishyang
站務副站長 發表:377 回覆:5490 積分:4563 註冊:2002-10-08 發送簡訊給我 |
|
turboted
版主 發表:95 回覆:754 積分:452 註冊:2002-07-23 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |