
首先,对于我来说,我对GUI编程非常陌生,尤其是C++生成器。我有一个包含一行单元格的tframe,就像上面的图片一样。有一个+按钮,当按下时,一个单元格只被添加到最后一列中,如下图所示。我想知道是否有可能在运行时更改tframe的大小,因为最后一列变得越来越大。tframe必须以一行单元格的大小开始。此框架不能有滚动条。当单元格被添加到最后一列时,它只需在高度上展开。
谢谢你的进阶。
更多信息。
下面是添加红细胞的tframe本身的编码(这也是另一个)。此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;
}
//---------------------------------------------------------------------------要解释这个有点棘手,所以如果你需要澄清的话,请告诉我,谢谢。
发布于 2012-02-15 23:29:34
与任何其他UI控件一样,TFrame发布了可以在设计时和运行时设置的Width和Height属性。
https://stackoverflow.com/questions/9266855
复制相似问题