首先,关于我,我对 GUI 编程非常陌生,尤其是使用 C++ Builder。我有一个包含一行单元格的 tframe,就像上面的图片一样。有一个 + 按钮,当按下时,一个单元格只会添加到最后一列,如图所示。我想知道是否可以在运行时更改 tframe 的大小,因为最后一列变得越来越大。tframe 必须从一行单元格的大小开始。此 tframe 不能有滚动条。随着单元格添加到最后一列,它只需要扩展高度。
提前致谢。
更多信息。
这是添加红细胞的 tframe 本身的编码(这也是另一个 tframe jsut fyi)。此 tframe 也被添加到滚动框中。为了更好地理解,请参阅Tree Structure with 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;
}
//---------------------------------------------------------------------------
解释这个有点棘手,所以如果你需要澄清,请告诉我,谢谢。