изменение размера tframe во время выполнения - PullRequest
1 голос
/ 13 февраля 2012

enter image description here

Во-первых, немного о себе, я очень новичок в программировании GUI, особенно в C ++ Builder.у меня есть tframe, который содержит ряд ячеек, как на картинке выше.есть кнопка +, и при нажатии ячейка добавляется только в последний столбец, как показано.Мне было интересно, можно ли изменить размер кадра во время выполнения, так как последний столбец становится все больше и больше.время начала должно быть размером с один ряд ячеек.для этого кадра не может быть полосы прокрутки.он просто должен увеличиваться по высоте при добавлении ячеек в последний столбец.

спасибо заранее.


больше информации.

Вот кодирование самого кадра, который добавляет красные ячейки (который также является другим tframe jsut fyi).этот кадр также добавляется в поле прокрутки.для лучшего понимания см. рисунок в Древовидная структура с TFrames .конечная цель - создать древовидную структуру кадров.

трейм в этом конкретном квесте - тфрейм справа от картинки с другим вопросом.

__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;
}
//---------------------------------------------------------------------------

это немного сложно объяснить, так что если тебе нужно пояснение, простодайте мне знать, спасибо.

1 Ответ

0 голосов
/ 16 февраля 2012

Как и любой другой элемент управления пользовательского интерфейса, TFrame опубликовал доступные свойства Width и Height, которые можно установить во время разработки и во время выполнения.

...