[英]changing the size of tframe at runtime
首先,關於我的一個小問題,我對GUI編程非常陌生,尤其是使用C ++ Builder時。 我有一個包含一行單元格的tframe,就像上面的圖片一樣。 有一個+按鈕,當按下時,僅將單元格添加到最后一列,如圖所示。 我想知道是否可以在運行時隨着最后一欄越來越大而更改tframe的大小。 tframe必須以一排單元格的大小開始。 此tframe沒有滾動條。 當單元格添加到最后一列時,它只需要在高度上擴展即可。
提前致謝。
更多信息。
這是添加紅細胞的tframe本身的編碼(這也是另一個tframe jsut fyi)。 此tframe也被添加到滾動框中。 為了更好的理解,請參閱帶有TFrames的樹結構中的圖片。 最終目標是創建tframe的樹結構。
此特定任務中的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;
}
//---------------------------------------------------------------------------
對此進行解釋有些棘手,所以如果您需要澄清,請告訴我,謝謝。
與其他任何UI控件一樣, TFrame
還發布了可用的Width
和Height
屬性,您可以在設計時和運行時進行設置。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.