Characteristics of the Buttoned Edit Control
|
|
The Images of the Control
|
|
The buttoned edit control is almost graphic-based. That
is, it uses an image list for its buttons. Consequently, you should create
an image list before applying it to control. A buttoned edit control can use
0, 1 or 2 buttons. In the same way, the image list used by a buttoned edit
control can contain just one or many pictures.
Each picture used in the image list of a buttoned edit
control should be big enough to fit a side of an edit control. It an image
is too big, it would be reduced to fit. This means that you should use
pictures that are 16x16 pixels or use that size when designing the pictures.
After creating the image list, to assign it to the
buttoned edit control, use the Images property of the
TCustomButtonedEdit class:
__property Controls::TImageList * Images = {read=FImages,write=SetImages};
As you can see, this property is of type
TImageList, which makes it possible to programmatically create the
image list.
Practical
Learning: Using Images
|
|
- In the Tool Palette, click Win32, click TImageList and click the
form
- Right-click the image list on the form and click ImageList Editor...
- Select in1.bmp, in2.bmp, Insert.bmp, out1.bmp, out2.bmp, Band.bmp,
down1.bmp, and up1.bmp
- Click OK
The Left and Right Buttons
|
|
Although it can appear by itself, the purpose of using a
buttoned edit control is to display a left and a right buttons, one on each
side of the control. Each of these button is an object of type
TEditButton. The TEditButton class is based on
TPersistent.
To identify its buttons, the button on the left side of
the edit box is represented by the LeftButton property of
the TCustomButtonedEdit class:
__property Extctrls::TEditButton * LeftButton =
{
read=FLeftButton,
write=SetLeftButton
};
The button on the right side is represented by the
RightButton property:
__property Extctrls::TEditButton * RightButton =
{
read=FRightButton,
write=SetRightButton
};
To access a particular button, get a reference to the
LeftButton or the RightButton property of
the buttoned edit control, then do what you need with it.
The Images on the Buttons
|
|
A button of the buttoned edit control can use 0, 1, or 2
pictures:
Remember that the pictures are set using indexes from
the list of images.
Practical
Learning: Configuring the Left and Right Buttons
|
|
- On the form, click each buttoned edit control and, using the Object
Inspector, set its Images to ImageList1
- Click each buttoned edit control and, from the Object Inspector,
change the following properties:
|
Control's Name |
LeftButton |
RightButton |
|
HotImageIndex |
ImageIndex |
PressedImageIndex |
HotImageIndex |
ImageIndex |
PressedImageIndex |
bedQuantitySedan |
2 |
0 |
6 |
2 |
1 |
7 |
bedManCostSedan |
5 |
4 |
6 |
5 |
3 |
7 |
bedQuantitySUV |
2 |
0 |
6 |
2 |
1 |
7 |
bedManCostSUV |
5 |
4 |
6 |
5 |
3 |
7 |
bedQuantityTrucks |
2 |
0 |
6 |
2 |
1 |
7 |
bedManCostTrucks |
5 |
4 |
6 |
5 |
3 |
7 |
bedQuantityMiniVans |
2 |
0 |
6 |
2 |
1 |
7 |
bedManCostMiniVans |
5 |
4 |
6 |
5 |
3 |
7 |
|
- In the lower section of the Code Editor, click Analysis.h
- Declare some variables and a method as follows:
private: // User declarations
int QuantitySedan, QuantitySUV, QuantityTrucks, QuantityMiniVans;
double ManCostSedan, ManCostSUV, ManCostTrucks, ManCostMiniVans;
double LowPriceSedan, HighPriceSedan, LowPriceSUV, HighPriceSUV,
double RevenuesSedan, RevenuesSUV, RevenuesTrucks, RevenuesMiniVans;
double TotalRevenues;
double TotalLowPrice, TotalHighPrice;
void __fastcall Calculate();
public: // User declarations
__fastcall TfrmAnalysis(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TfrmAnalysis *frmAnalysis;
//---------------------------------------------------------------------------
#endif
- Click the Analysis.cpp tab and define the method as follows:
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Analysis.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TfrmAnalysis *frmAnalysis;
//---------------------------------------------------------------------------
__fastcall TfrmAnalysis::TfrmAnalysis(TComponent* Owner)
: TForm(Owner)
{
// The following are just random values
QuantitySedan = 8246;
QuantitySUV = 2875;
QuantityTrucks = 4606;
QuantityMiniVans = 4217;
ManCostSedan = 18580.00;
ManCostSUV = 24505.00;
ManCostTrucks = 16425.00;
ManCostMiniVans = 22875.00;
RevenuesSedan = 0.00;
RevenuesSUV = 0.00;
RevenuesTrucks = 0.00;
RevenuesMiniVans = 0.00;
TotalRevenues = 0.00;
}
//---------------------------------------------------------------------------
void __fastcall TfrmAnalysis::Calculate()
{
QuantitySedan = StrToInt(this->bedQuantitySedan->Text);
QuantitySUV = StrToInt(this->bedQuantitySUV->Text);
QuantityTrucks = StrToInt(this->bedQuantityTrucks->Text);
QuantityMiniVans = StrToInt(this->bedQuantityMiniVans->Text);
ManCostSedan = StrToFloat(this->bedManCostSedan->Text);
ManCostSUV = StrToFloat(this->bedManCostSUV->Text);
ManCostTrucks = StrToFloat(this->bedManCostTrucks->Text);
ManCostMiniVans = StrToFloat(this->bedManCostMiniVans->Text);
RevenuesSedan = QuantitySedan * ManCostSedan;
RevenuesSUV = QuantitySUV * ManCostSUV;
RevenuesTrucks = QuantityTrucks * ManCostTrucks;
RevenuesMiniVans = QuantityMiniVans * ManCostMiniVans;
TotalRevenues = RevenuesSedan + RevenuesSUV +
RevenuesTrucks + RevenuesMiniVans;
this->edtRevenuesSedan->Text = FloatToStrF(RevenuesSedan,
ffNumber, 20, 2);
this->edtRevenuesSUV->Text = FloatToStrF(RevenuesSUV,
ffNumber, 20, 2);
this->edtRevenuesTrucks->Text = FloatToStrF(RevenuesTrucks,
ffNumber, 20, 2);
this->edtRevenuesMiniVans->Text = FloatToStrF(RevenuesMiniVans,
ffNumber, 20, 2);
this->edtTotalRevenues->Text = FloatToStrF(TotalRevenues,
ffNumber, 20, 2);
}
//---------------------------------------------------------------------------
- Press F12 to display the form
- Double-click an unoccupied area of the form to generate its OnCreate
event
- Implement it as follows:
//---------------------------------------------------------------------------
void __fastcall TfrmAnalysis::FormCreate(TObject *Sender)
{
this->bedQuantitySedan->Text = IntToStr(QuantitySedan);
this->bedQuantitySUV->Text = IntToStr(QuantitySUV);
this->bedQuantityTrucks->Text = IntToStr(QuantityTrucks);
this->bedQuantityMiniVans->Text = IntToStr(QuantityMiniVans);
this->bedManCostSedan->Text = FloatToStr(ManCostSedan);
this->bedManCostSUV->Text = FloatToStr(ManCostSUV);
this->bedManCostTrucks->Text = FloatToStr(ManCostTrucks);
this->bedManCostMiniVans->Text = FloatToStr(ManCostMiniVans);
Calculate();
}
//---------------------------------------------------------------------------
- Press F12 to return to the form
- double-click the first buttoned edit control under Quantity to
generate its OnChange event
- Implement the event as follows:
//---------------------------------------------------------------------------
void __fastcall TfrmAnalysis::bedQuantitySedanChange(TObject *Sender)
{
QuantitySedan = StrToInt(this->bedQuantitySedan->Text);
}
//---------------------------------------------------------------------------
- In the top combo box of the Object Inspector, select
bedQuantitySedan
- In the Object Inspector, click Events and double-click
OnLeftButtonClick
- Implement the event as follows:
//---------------------------------------------------------------------------
void __fastcall TfrmAnalysis::bedQuantitySedanLeftButtonClick(TObject *Sender)
{
int RndNumber = Random(3);
switch(RndNumber)
{
case 1:
this->imgCar->Picture->LoadFromFile("sedan1.bmp");
break;
case 2:
this->imgCar->Picture->LoadFromFile("sedan2.bmp");
break;
default:
this->imgCar->Picture->LoadFromFile("sedan3.bmp");
break;
}
QuantitySedan--;
bedQuantitySedan->Text = IntToStr(QuantitySedan);
Calculate();
}
//---------------------------------------------------------------------------
- In the Events section of the Object Inspector, double-click
OnRightButtonClick
- Implement the event as follows:
//---------------------------------------------------------------------------
void __fastcall TfrmAnalysis::bedQuantitySedanRightButtonClick(TObject *Sender)
{
int RndNumber = Random(3);
switch(RndNumber)
{
case 1:
this->imgCar->Picture->LoadFromFile("sedan1.bmp");
break;
case 2:
this->imgCar->Picture->LoadFromFile("sedan2.bmp");
break;
default:
this->imgCar->Picture->LoadFromFile("sedan3.bmp");
break;
}
QuantitySedan++;
bedQuantitySedan->Text = IntToStr(QuantitySedan);
Calculate();
}
//---------------------------------------------------------------------------
- In the top combo box of the Object Inspector, select bedManCostSedan
- In the Events section of the Object Inspector, double-click OnChange
- Implement the event as follows:
//---------------------------------------------------------------------------
void __fastcall TfrmAnalysis::bedManCostSedanChange(TObject *Sender)
{
ManCostSedan = StrToFloat(this->bedManCostSedan->Text);
}
//---------------------------------------------------------------------------
- In the Events section of the Object Inspector, double-click
OnLeftButtonClick
- Implement the event as follows:
//---------------------------------------------------------------------------
void __fastcall TfrmAnalysis::bedManCostSedanLeftButtonClick(TObject *Sender)
{
ManCostSedan--;
this->bedManCostSedan->Text = FloatToStr(ManCostSedan);
Calculate();
}
//---------------------------------------------------------------------------
- In the Events section of the Object Inspector, double-click
OnRightButtonClick
- Implement the event as follows:
//---------------------------------------------------------------------------
void __fastcall TfrmAnalysis::bedManCostSedanRightButtonClick(TObject *Sender)
{
ManCostSedan++;
this->bedManCostSedan->Text = FloatToStr(ManCostSedan);
Calculate();
}
//---------------------------------------------------------------------------
- In the top combo box of the Object Inspector, select bedQuantitySUV
- In the Events section of the Object Inspector, double-click OnChange
- Implement the event as follows:
//---------------------------------------------------------------------------
void __fastcall TfrmAnalysis::bedQuantitySUVChange(TObject *Sender)
{
QuantitySUV = StrToInt(this->bedQuantitySUV->Text);
}
//---------------------------------------------------------------------------
- In the Events section of the Object Inspector, double-click
bedQuantityTrucks
- Implement the event as follows:
//---------------------------------------------------------------------------
void __fastcall TfrmAnalysis::bedQuantitySUVLeftButtonClick(TObject *Sender)
{
QuantitySUV--;
bedQuantitySUV->Text = IntToStr(QuantitySUV);
Calculate();
}
//---------------------------------------------------------------------------
- In the Events section of the Object Inspector, double-click
OnRightButtonClick
- Implement the event as follows:
//---------------------------------------------------------------------------
void __fastcall TfrmAnalysis::bedQuantitySUVRightButtonClick(TObject *Sender)
{
QuantitySUV++;
bedQuantitySUV->Text = IntToStr(QuantitySUV);
Calculate();
}
//---------------------------------------------------------------------------
- In the top combo box of the Object Inspector, select bedManCostSedan
- In the Events section of the Object Inspector, double-click OnChange
- Implement the event as follows:
//---------------------------------------------------------------------------
void __fastcall TfrmAnalysis::bedManCostSUVChange(TObject *Sender)
{
ManCostSUV = StrToFloat(this->bedManCostSUV->Text);
}
//---------------------------------------------------------------------------
- In the Events section of the Object Inspector, double-click
OnLeftButtonClick
- Implement the event as follows:
//---------------------------------------------------------------------------
void __fastcall TfrmAnalysis::bedManCostSUVLeftButtonClick(TObject *Sender)
{
int RndNumber = Random(3);
switch(RndNumber)
{
case 1:
this->imgCar->Picture->LoadFromFile("suv1.bmp");
break;
case 2:
this->imgCar->Picture->LoadFromFile("suv2.bmp");
break;
default:
this->imgCar->Picture->LoadFromFile("suv3.bmp");
break;
}
ManCostSUV--;
this->bedManCostSUV->Text = FloatToStr(ManCostSUV);
Calculate();
}
//---------------------------------------------------------------------------
- In the Events section of the Object Inspector, double-click
OnRightButtonClick
- Implement the event as follows:
//---------------------------------------------------------------------------
void __fastcall TfrmAnalysis::bedManCostSUVRightButtonClick(TObject *Sender)
{
int RndNumber = Random(3);
switch(RndNumber)
{
case 1:
this->imgCar->Picture->LoadFromFile("suv1.bmp");
break;
case 2:
this->imgCar->Picture->LoadFromFile("suv2.bmp");
break;
default:
this->imgCar->Picture->LoadFromFile("suv3.bmp");
break;
}
ManCostSUV++;
this->bedManCostSUV->Text = FloatToStr(ManCostSUV);
Calculate();
}
//---------------------------------------------------------------------------
- In the top combo box of the Object Inspector, select
bedQuantityTrucks
- In the Events section of the Object Inspector, double-click OnChange
- Implement the event as follows:
//---------------------------------------------------------------------------
void __fastcall TfrmAnalysis::bedQuantityTrucksChange(TObject *Sender)
{
QuantityTrucks = StrToInt(this->bedQuantityTrucks->Text);
}
//---------------------------------------------------------------------------
- In the Events section of the Object Inspector, double-click
OnLeftButtonClick
- Implement the event as follows:
//---------------------------------------------------------------------------
void __fastcall TfrmAnalysis::bedQuantityTrucksLeftButtonClick(TObject *Sender)
{
int RndNumber = Random(3);
switch(RndNumber)
{
case 1:
this->imgCar->Picture->LoadFromFile("truck1.bmp");
break;
case 2:
this->imgCar->Picture->LoadFromFile("truck2.bmp");
break;
default:
this->imgCar->Picture->LoadFromFile("truck3.bmp");
break;
}
QuantityTrucks--;
bedQuantityTrucks->Text = IntToStr(QuantityTrucks);
Calculate();
}
//---------------------------------------------------------------------------
- In the Events section of the Object Inspector, double-click
OnRightButtonClick
- Implement the event as follows:
//---------------------------------------------------------------------------
void __fastcall TfrmAnalysis::bedQuantityTrucksRightButtonClick(TObject *Sender)
{
int RndNumber = Random(3);
switch(RndNumber)
{
case 1:
this->imgCar->Picture->LoadFromFile("truck1.bmp");
break;
case 2:
this->imgCar->Picture->LoadFromFile("truck2.bmp");
break;
default:
this->imgCar->Picture->LoadFromFile("truck3.bmp");
break;
}
QuantityTrucks++;
bedQuantityTrucks->Text = IntToStr(QuantityTrucks);
Calculate();
}
//---------------------------------------------------------------------------
- In the top combo box of the Object Inspector, select
bedManCostTrucks
- In the Events section of the Object Inspector, double-click OnChange
- Implement the event as follows:
//---------------------------------------------------------------------------
void __fastcall TfrmAnalysis::bedManCostTrucksChange(TObject *Sender)
{
ManCostTrucks = StrToFloat(this->bedManCostTrucks->Text);
}
//---------------------------------------------------------------------------
- In the Events section of the Object Inspector, double-click
OnLeftButtonClick
- Implement the event as follows:
//---------------------------------------------------------------------------
void __fastcall TfrmAnalysis::bedManCostTrucksLeftButtonClick(TObject *Sender)
{
int RndNumber = Random(3);
switch(RndNumber)
{
case 1:
this->imgCar->Picture->LoadFromFile("truck1.bmp");
break;
case 2:
this->imgCar->Picture->LoadFromFile("truck2.bmp");
break;
default:
this->imgCar->Picture->LoadFromFile("truck3.bmp");
break;
}
ManCostTrucks--;
this->bedManCostTrucks->Text = FloatToStr(ManCostTrucks);
Calculate();
}
//---------------------------------------------------------------------------
- In the Events section of the Object Inspector, double-click
OnRightButtonClick
- Implement the event as follows:
//---------------------------------------------------------------------------
void __fastcall TfrmAnalysis::bedManCostTrucksRightButtonClick(TObject *Sender)
{
int RndNumber = Random(3);
switch(RndNumber)
{
case 1:
this->imgCar->Picture->LoadFromFile("truck1.bmp");
break;
case 2:
this->imgCar->Picture->LoadFromFile("truck2.bmp");
break;
default:
this->imgCar->Picture->LoadFromFile("truck3.bmp");
break;
}
ManCostTrucks++;
this->bedManCostSedan->Text = FloatToStr(ManCostTrucks);
Calculate();
}
//---------------------------------------------------------------------------
- In the Events section of the Object Inspector, double-click
bedQuantityMiniVans
- Implement the event as follows:
//---------------------------------------------------------------------------
void __fastcall TfrmAnalysis::bedQuantityMiniVansChange(TObject *Sender)
{
QuantityMiniVans = StrToInt(this->bedQuantityMiniVans->Text);
}
//---------------------------------------------------------------------------
- In the Events section of the Object Inspector, double-click
OnLeftButtonClick
- Implement the event as follows:
//---------------------------------------------------------------------------
void __fastcall TfrmAnalysis::bedQuantityMiniVansLeftButtonClick(TObject *Sender)
{
int RndNumber = Random(3);
switch(RndNumber)
{
case 1:
this->imgCar->Picture->LoadFromFile("minivan1.bmp");
break;
case 2:
this->imgCar->Picture->LoadFromFile("minivan2.bmp");
break;
default:
this->imgCar->Picture->LoadFromFile("minivan3.bmp");
break;
}
QuantityMiniVans--;
bedQuantityMiniVans->Text = IntToStr(QuantityMiniVans);
Calculate();
}
//---------------------------------------------------------------------------
- In the Events section of the Object Inspector, double-click
OnRightButtonClick
- Implement the event as follows:
//---------------------------------------------------------------------------
void __fastcall TfrmAnalysis::bedQuantityMiniVansRightButtonClick(TObject *Sender)
{
int RndNumber = Random(3);
switch(RndNumber)
{
case 1:
this->imgCar->Picture->LoadFromFile("minivan1.bmp");
break;
case 2:
this->imgCar->Picture->LoadFromFile("minivan2.bmp");
break;
default:
this->imgCar->Picture->LoadFromFile("minivan3.bmp");
break;
}
QuantityMiniVans++;
bedQuantityMiniVans->Text = IntToStr(QuantityMiniVans);
Calculate();
}
//---------------------------------------------------------------------------
- In the top combo box of the Object Inspector, select
bedManCostMiniVans
- In the Events section of the Object Inspector, double-click OnChange
- Implement the event as follows:
//---------------------------------------------------------------------------
void __fastcall TfrmAnalysis::bedManCostMiniVansChange(TObject *Sender)
{
ManCostMiniVans = StrToFloat(this->bedManCostMiniVans->Text);
}
//---------------------------------------------------------------------------
- In the Events section of the Object Inspector, double-click
OnLeftButtonClick
- Implement the event as follows:
//---------------------------------------------------------------------------
void __fastcall TfrmAnalysis::bedManCostMiniVansLeftButtonClick(TObject *Sender)
{
ManCostMiniVans--;
this->bedManCostMiniVans->Text = FloatToStr(ManCostMiniVans);
Calculate();
}
//---------------------------------------------------------------------------
- In the Events section of the Object Inspector, double-click
OnRightButtonClick
- Implement the event as follows:
//---------------------------------------------------------------------------
void __fastcall TfrmAnalysis::bedManCostMiniVansRightButtonClick(TObject *Sender)
{
ManCostMiniVans++;
this->bedManCostMiniVans->Text = FloatToStr(ManCostMiniVans);
Calculate();
}
//---------------------------------------------------------------------------
- Press F9 to test the application
- Close the form and return to your programming environment
A Popup Menu For a button
|
|
You can display a popup menu when a button is clicked.
This is possible because the TEditButton class provides the
DropDownMenu property that is of type TPopupMenu:
__property Menus::TPopupMenu * DropDownMenu = {read=FDropDownMenu,write=FDropDownMenu};
If you want a button to display a menu, first click a
TPopupMenu
,
then assign it to the DropDownMenu property of the desired
button.
|
|