The simplest static control is considered a label. It
consists of a simple object that displays text. The user cannot directly
change this text unless you programmatically allow it. This form of the
static control is the simplest control you can use in a VCL application.
To add a simple label to a dialog box, you can click
the Label button on the Standard tab of the Component Palette. The only thing you need to do is to change the Caption property on
the Object Inspector window.
If you cannot add a label to the dialog box when
designing it, you can programmatically create one. This is done using the TLabel
class and calling its constructor.
|
Practical Learning: Starting the Exercise |
|
- Start Borland C++ Builder and create a new application
- To start saving the application, on the Standard toolbar, click the
Save All button. Create a new folder named ColorChanger1 and
display it in the Save In combo box
- Save the unit as Main and save the project as ColorChanger
- Design the dialog box as follows:
|
Control |
Name |
Caption |
Additional Properties |
Form |
|
frmMain |
Color Changer |
BorderStyle: bsDialog
Position: poScreenCenter |
Panel |
|
pnlPreview |
None |
Color: clSilver |
TrackBar |
|
trcRed |
|
Frequency: 20
Max: 255
Orientation: trVertical
Position: 63
TickMarks: tmBoth |
TrackBar |
|
trcGreen |
|
Frequency: 20
Max: 255
Orientation: trVertical
Position: 63
TickMarks: tmBoth |
TrackBar |
|
trcBlue |
|
Frequency: 20
Max: 255
Orientation: trVertical
Position: 63
TickMarks: tmBoth |
BitBtn |
|
|
|
Kind: bkClose |
Label |
|
lblRed |
192 |
Alignment: taCenter |
Label |
|
lblGreen |
192 |
Alignment: taCenter |
Label |
|
lblBlue |
192 |
Alignment: taCenter |
|
- Save All
- On the form, double-click the left track bar and implement its OnChange
event as follows:
//---------------------------------------------------------------------------
void __fastcall TfrmMain::trcRedChange(TObject *Sender)
{
int iRed = 255 - trcRed->Position;
int iGreen = 255 - trcGreen->Position;
int iBlue = 255 - trcBlue->Position;
pnlPreview->Color = TColor(RGB(iRed, iGreen, iBlue));
lblRed->Caption = IntToStr(iRed);
}
//---------------------------------------------------------------------------
|
- On the form, double-click the middle track bar and implement its OnChange
event as follows:
//---------------------------------------------------------------------------
void __fastcall TForm1::trcGreenChange(TObject *Sender)
{
int iRed = 255 - trcRed->Position;
int iGreen = 255 - trcGreen->Position;
int iBlue = 255 - trcBlue->Position;
pnlPreview->Color = TColor(RGB(iRed, iGreen, iBlue));
lblGreen->Caption = IntToStr(iGreen);
}
//---------------------------------------------------------------------------
|
- On the form, double-click the right track bar and implement its OnChange
event as follows:
//---------------------------------------------------------------------------
void __fastcall TfrmMain::trcBlueChange(TObject *Sender)
{
int iRed = 255 - trcRed->Position;
int iGreen = 255 - trcGreen->Position;
int iBlue = 255 - trcBlue->Position;
pnlPreview->Color = TColor(RGB(iRed, iGreen, iBlue));
lblBlue->Caption = IntToStr(iBlue);
}
//---------------------------------------------------------------------------
|
- Test the application
- After using it, close it and return to your programming environment.
|
|
|