How to put a progress bar on a Status Bar c++ builder
Question and Answer Database
FAQ2293C.txt How to put a progress bar on a Status Bar ...
Category :VCL
Platform :All
Product :C++Builder 3.x
Question:
How Do I put a Proress bar on a status bar.
Answer:
Here is an example:
This is the form:
object Form1: TForm1
Left = 191
Top = 108
Width = 226
Height = 140
Caption = 'Form1'
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
OnCreate = FormCreate
PixelsPerInch = 96
TextHeight = 13
object StatusBar1: TStatusBar
Left = 0
Top = 94
Width = 218
Height = 19
Panels =
SimplePanel = False
OnResize = StatusBar1Resize
end
object Button1: TButton
Left = 18
Top = 30
Width = 75
Height = 25
Caption = 'Button1'
TabOrder = 1
OnClick = Button1Click
end
end
//----------------------------------------------------------
This is unit1.cpp
//---------------------------------------------------------------------------
#include
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
ProgressBar = new TProgressBar ( StatusBar1 );
ProgressBar->Parent = StatusBar1;
ProgressBar->Position = 0;
ProgressBar->Visible = false;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::StatusBar1Resize(TObject *Sender)
{
int Size = StatusBar1->Width;
for ( int i = 1; i Panels->Count; i++ )
Size -= StatusBar1->Panels->Items[i]->Width;
//resize the first panel based on the form width
StatusBar1->Panels->Items[ 0 ]->Width = Size;
RECT Rect;
StatusBar1->Perform ( SB_GETRECT, 0, (LPARAM)&Rect );
ProgressBar->Top = Rect.top;
ProgressBar->Left = Rect.left;
ProgressBar->Width = StatusBar1->Panels->Items [ 0 ]->Width;
ProgressBar->Height = Rect.bottom - Rect.top;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
ProgressBar->Show();
ProgressBar->Position = 50;
}
//---------------------------------------------------------------------------
Here is Unit1.h
//---------------------------------------------------------------------------
#ifndef Unit1H
#define Unit1H
//---------------------------------------------------------------------------
#include
#include
#include
#include
#include
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published: // IDE-managed Components
TStatusBar *StatusBar1;
TButton *Button1;
void __fastcall FormCreate(TObject *Sender);
void __fastcall StatusBar1Resize(TObject *Sender);
void __fastcall Button1Click(TObject *Sender);
private: // User declarations
TProgressBar *ProgressBar;
public: // User declarations
__fastcall TForm1(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif
7/2/98 10:32:32 AM