1
改變TFRAME的大小首先,一個關於我的律,我很新的GUI編程,特別是C++ Builder中。我有一個包含一排單元格的tframe,就像上面的圖片一樣。有一個+按鈕,當按下時,單元格僅被添加到最後一列,如圖所示。我想知道在最後一列變得越來越大的時候,是否可以在運行時更改tframe的大小。該tframe必須從一行單元的大小開始。這個tframe沒有滾動條。它只需將單元格添加到最後一列時的高度進行擴展。
感謝先進。
更多信息。
這裏是tframe本身的編碼,它添加了紅色單元(這也是另一個tframe jsut fyi)。這個tframe也被添加到滾動框中。爲了更好地理解,請參考Tree Structure with TFrames中的圖片。最終目標是創建一個tframes的樹結構。
在這個特定任務中的tframe是另一個問題圖片中最右邊的tframe。
__fastcall TTreeTframe::TTreeTframe(TComponent* Owner)
: TFrame(Owner)
{
AddCells();
}
//---------------------------------------------------------------------------
void __fastcall TTreeTframe::AddCells()
{
//this part adds the cells in the tframe (red boxes in the picture)
int tempCellRow = 0;
TCells* NewCellRow = new TCells (this);
NewCellRow->Parent=this;
TComponentEnumerator * ParentEnum = this->GetEnumerator();
while(ParentEnum->MoveNext())
{
tempCellRow++;
}
NewCellRow->SetIndex(tempCellRow);
NewCellRow->Name = "Cell" + IntToStr(tempCellRow);
NewCellRow->Top = (NewCellRow->Height) * (tempCellRow-9);
NewCellRow->Left = 213;
NewCellRow->OnClose = &DeleteCell;
}
void __fastcall TTreeTframe::DeleteCell(TObject *Sender)
{
//this part deletes the cells when the delete button is pressed. As
//mentioned the red boxes themselves are also tframe, and in that
//tframe is a TEdit with a delete button. just so u know where the
//delete button is located
TCells* TCurrent = NULL;
int CellRow = 0;
TCells* NewCellRow = (TCells*)Sender;
CellRow = NewCellRow->GetIndex();
NewCellRow->Name = "";
TComponentEnumerator * ParentEnum = NewCellRow->Parent->GetEnumerator();
while(ParentEnum->MoveNext())
{
TCurrent = (TCells*)ParentEnum->GetCurrent();
if(TCurrent->GetIndex() > CellRow)
{
TCurrent->SetIndex(TCurrent->GetIndex() - 1);
TCurrent->Top -= (NewCellRow->Height);
TCurrent->Name = "DistIPCell" + IntToStr(TCurrent->GetIndex());
}
}
}
//---------------------------------------------------------------------------
void __fastcall TTreeTframe::btnAddCellsClick(TObject *Sender)
{
// this is what the red + does
AddCells();
}
//---------------------------------------------------------------------------
// the rest of this is for the propose of deleting this tframe from the tree structure
void __fastcall TTreeTframe::btnRemoveClick(TObject *Sender)
{
if (FOnClose != NULL)
{
FOnClose(this);
}
PostMessage(Handle, CM_RELEASE, 0, 0);
}
//---------------------------------------------------------------------------
void __fastcall TTreeTframe::WndProc(TMessage &Message)
{
if (Message.Msg == CM_RELEASE)
{
delete this;
return;
}
TFrame::WndProc(Message);
}
//---------------------------------------------------------------------------
void __fastcall TTreeTframe::SetIndex(int TypeRow)
{
this->TypeRow = TypeRow;
}
int __fastcall TTreeTframe::GetIndex()
{
return this->TypeRow;
}
//---------------------------------------------------------------------------
解釋這件事有點棘手,所以如果你需要澄清,請讓我知道,謝謝。
o就像TFrame-> Height,但是當我點擊添加時設置它?非常感謝您的幫助,我的realyl幫助我很多這個項目。我感到非常愚蠢的問這麼多的問題,你一直不得不幫助我,但就像我說我以前沒有觸及任何基於此,這對我來說是一個非常巨大的學習體驗 – livelaughlove 2012-02-16 06:52:11
'TFrame'也有一個'AutoSize'可用的屬性,您可以將其設置爲「true」。然後,您不必手動調整「高度」。 – 2012-02-16 20:40:45
嘿,我一直在努力讓這個工作。我在tframe上檢查了AutoSize,但它在運行時不會調整大小。單元格被正確添加,只是框架沒有變大。我必須爲OnResize()事件實現一些東西,還是缺少其他東西? – livelaughlove 2012-03-07 18:55:25