2012-11-03 35 views
0

我想創建一個組件,但我不滿意Align工作方式,所以我想創建自己的屬性以完全不同的方式重新定位組件。 但我不確定在哪裏與它掛鉤 - 它應該在哪裏被調用?如何創建具有自定義對齊過程的組件?

+0

你想如何表現? – NGLN

+0

類似於真實對齊的東西,但我希望組件重疊。 – Tom

+3

示例:http://cc.embarcadero.com/item/17340 –

回答

1

article由史蒂夫Trefethen,前Borland的開發,展示瞭如何使用alCustom

2

一個快速訪問將覆蓋的setBounds,以確保它是叫你沃爾德必須設置一個比對的其他然後alNone

type 
    TMyButton=Class(Tbutton) 
     procedure SetBounds(ALeft, ATop, AWidth, AHeight: Integer); override; 

    End; 

//.............. 


procedure TForm3.Button1Click(Sender: TObject); 
begin 
    With TMyButton.Create(self) do 
    begin 
     Parent := self; 
     Width := 200; 
     top := 100; 
     Height := 100; 
     align := alCustom; // was alRight thanks to David Heffernan 
    end; 
end; 


{ TMyButton } 

procedure TMyButton.SetBounds(ALeft, ATop, AWidth, AHeight: Integer); 
begin 
    if Assigned(parent) then 
     begin // .. just e.g. 
     ALeft := Parent.Width - Width -100 ; 
     ATop := 100; 
     AHeight := Parent.Height - Atop - 100 ; 
     end; 
    inherited; 

end; 
+0

這不太好。例如,當Parent改變其大小時,我的組件的SetBounds不會被觸發,因此它不能重新定位它自己。 – Tom

+0

在我的環境中調整問題的方法是正確的,但是你是對的,maxi /最小化問題 – bummi

+0

我再次嘗試使用Delphi XE,如果將AWith設置爲和定義的對齊工作正常。沒有對齊如alRight Setbounds不會根據需要調用。 – bummi