1

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.

Community
  • 1
  • 1
livelaughlove
  • 376
  • 3
  • 9
  • 21

1 Answers1

0

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

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
  • o so just like TFrame->Height , but set it when i click add? thanks very much for your help u'r realyl helpign me alot with this project. i feel pretty silly asking so many questions and u keep having to help me but like i said i haven't touched base on any of this before, it's been a really huge learning experience for me – livelaughlove Feb 16 '12 at 06:52
  • 1
    `TFrame` also has an `AutoSize` property available that you could set to `true` instead. Then you do not have to adjust the `Height` manually. – Remy Lebeau Feb 16 '12 at 20:40
  • hey i've been trying to get this to work. I have AutoSize checked on the tframe, but it doesn't resize during runtime. The cells are added properly, just that the frame doesn't get any bigger. would i have to implement something for the OnResize() Event or am i missing something something else? – livelaughlove Mar 07 '12 at 18:55
  • Please show your actual code that is filling in the `TFrame`. Also, which version of C++Builder are you using? – Remy Lebeau Mar 07 '12 at 18:59
  • I've edited my question with more code. hopefully it's not confusing. I'm using C++ Builder XE. really thank you for your help, and ur patience – livelaughlove Mar 07 '12 at 19:31