【问题标题】:changing the size of tframe at runtime在运行时更改 tframe 的大小
【发布时间】:2012-03-05 05:29:28
【问题描述】:

首先,关于我,我对 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;
}
//---------------------------------------------------------------------------

解释起来有点棘手,所以如果您需要澄清,请告诉我,谢谢。

【问题讨论】:

    标签: c++ user-interface runtime c++builder tframe


    【解决方案1】:

    与任何其他 UI 控件一样,TFrame 发布了可用的 WidthHeight 属性,您可以在设计时和运行时设置它们。

    【讨论】:

    • o 就像 TFrame->Height 一样,但是当我点击添加时设置它?非常感谢您对这个项目的帮助。我觉得问这么多问题很傻,你总是要帮助我,但就像我说的我以前没有接触过这些,这对我来说是一次非常重要的学习经历
    • TFrame 也有一个可用的AutoSize 属性,您可以将其设置为true。那么你就不必手动调整Height了。
    • 嘿,我一直在努力让它发挥作用。我在 tframe 上检查了 AutoSize,但它在运行时不会调整大小。正确添加了单元格,只是框架没有变大。我必须为 OnResize() 事件实现一些东西还是我错过了其他东西?
    • 请出示您填写TFrame的实际代码。另外,您使用的是哪个版本的 C++Builder?
    • 我已经用更多代码编辑了我的问题。希望它不会令人困惑。我正在使用 C++ Builder XE。非常感谢您的帮助和耐心
    猜你喜欢
    • 1970-01-01
    • 2012-03-22
    • 1970-01-01
    • 2011-05-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-07
    相关资源
    最近更新 更多