2012-02-13 18 views
1

enter image description hereでTFrameのサイズを変更するランタイム

まず第一に、私についてのlilのは、私は特にC++ Builderで、GUIプログラミングに非常に新しいです。私は上記の画像のように、セルの行を含むtframeを持っています。 +ボタンがあり、押されるとセルは図のように最後の列に追加されます。最後の列が大きくなるにつれて、実行時にtframeのサイズを変更することが可能かどうか疑問に思っていました。 tframeは1行のセルのサイズになるように開始する必要があります。このtframeのスクロールバーは存在しません。セルが最後の列に追加されると、高さが拡張されます。

ありがとうございました。


詳細情報

ここに赤いセルを追加するtframe自体のコーディングがあります(別のtframe jsut fyiです)。このtframeもスクロールボックスに追加されています。より良い理解のためにTree Structure with TFramesの画像を参照してください。最終的な目標は、tframesのツリー構造を作成することです。

この特定のクエストのtframeは、もう1つの質問の画像の中で最も右側の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; 
} 
//--------------------------------------------------------------------------- 

これを説明するのはやや難しいので、明確にする必要がある場合はお知らせください。ありがとうございます。

答えて

0

その他のUIコントロールと同様に、TFrameは、デザインタイムと実行時に設定できるWidthHeightプロパティを公開しています。

+0

o TFrame-> Heightと似ていますが、追加をクリックすると設定されますか?あなたの助けを借りて本当に感謝しています。私はかなり愚かなことを多くの質問をしていると私は助けを続けなければならないと感じるが、私は前にこれのいずれかのベースに触れていないと言ったように、それは私のための本当に巨大な学習経験されている – livelaughlove

+1

'TFrame'も' AutoSize'代わりに 'true'に設定できるプロパティがあります。次に、 'Height'を手動で調整する必要はありません。 –

+0

ねえ、私はこれを働かせようとしてきました。私はtframeでAutoSizeをチェックしましたが、実行時にはサイズが変更されません。細胞は、フレームがそれ以上大きくならないように、適切に追加されます。私はOnResize()イベントのために何かを実装する必要がありますか何か他の何かを逃していますか? – livelaughlove