Domanda

enter image description here

First off, a lil about me, i'm very new to GUI programming, especially with C++ Builder. i have a tframe that contains a row of cells, just like the picture above. there is a + button, and when pressed a cell is only added to the last column as shown. I was wondering if it is possible to change the size of the tframe during run time as the last column gets bigger and bigger. the tframe has to start off to be the size of one row of cells. there can be no scrollbar for this tframe. it simply has to expand in height as cells are added to the last column.

thanks in advanced.


more info.

here's the coding for the tframe itself that adds the red cells (which is also another tframe jsut fyi). this tframe is also being added to a scroll box. for a better understanding refer to the picture in Tree Structure with TFrames. the ultimate goal is to create a tree structure of tframes.

the tframe in this particular quest is the tframe to the most right in the picture of the other question.

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

it's a bit tricky to explain this, so if u need clarification just let me know, thanks.

È stato utile?

Soluzione

Like any other UI control, TFrame has published Width and Height properties available that you can set at design-time and at run-time.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top