Home

VCL Controls: The Buttoned Edit Control

 

Introduction to the Buttoned Edit Control

 

Description

A buttoned edit control is an object that adds two buttons to an edit box so the whole combination is treated as one control. The edit box has one button to its left and another to its right. Each button is a complete button of its own; that is, it has all the normal characteristics of a Microsoft Windows button. In the same way, the edit box uses all the necessary features of a text box.

 

Practical LearningPractical Learning: Introducing Buttoned Edit Controls

The application we are going to create allows a fictitious car manufacturer to make projections of what it would earn, based on different categories of cars. The company uses that simulation to find out what it would get if it increases (or decreases) the number of cars produced in a certain category and what would happen if it increases (or decreases) the cost of producing that category of cars; that is, what impact the quantity and the cost would have on the company's revenues.

  1. To start a new application, on the main menu, click File -> Other...
  2. In the left list of the New Items dialog box, click C++Builder Projects.
    In the right list, click VCL Forms Application
  3. While the default form is selected, in the Object Inspector, change its properties as follows:
    Caption: Car Manufacture Analysis
    Name: frmAnalysis
    Position: poScreenCenter

 

Creating a Buttoned Edit Control

To apply the description of a buttoned edit control, the VCL provides the TButtonedEdit class. This class simply implements the TCustomButtonedEdit class. The TCustomButtonedEdit class is based on TCustomEdit that is derived from the TWinControl class:

TButtonedEdit Inheritance

To visually add a buttoned edit control, in the Additional section, click the TButtonedEdit icon TButtonedEdit and click the form or container. To programmatically get a buttoned edit control, create a pointer to TButtonedEdit and initialize it using its constructor. Also, specify the control's parent. Here is an example:

Header File

//---------------------------------------------------------------------------

#ifndef Unit1H
#define Unit1H
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published:	// IDE-managed Components
private:	// User declarations
	TButtonedEdit * bedAnalysis;

public:		// User declarations
	__fastcall TForm1(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif

Source File

//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
	: TForm(Owner)
{
	bedAnalysis = new TButtonedEdit(this);
	bedAnalysis->Parent = this;
}
//---------------------------------------------------------------------------

Practical LearningPractical Learning: Creating Buttoned Edit Controls

  1. Design the form as follows:
     
    Car Manufacture Analysis
    Control Alignment Caption/Text Name Kind
    TLabel TLabel   Category    
    TLabel TLabel   Quantity    
    TLabel TLabel   Manufacture Cost    
    TLabel TLabel   Revenue    
    TLabel TLabel   Sedans:    
    TButtonedEdit TButtonedEdit taCenter 0 bedQuantitySedan  
    TButtonedEdit TButtonedEdit taCenter 0 bedManCostSedan  
    TEdit TSpeedButton taRightJustify 0.00 edtRevenuesSedan  
    TLabel TLabel   SUVs:    
    TButtonedEdit TButtonedEdit taCenter 0 bedQuantitySUV  
    TButtonedEdit TButtonedEdit taCenter 0 bedManCostSUV  
    TEdit TSpeedButton taRightJustify 0.00 edtRevenuesSUV  
    TLabel TLabel   Trucks:    
    TButtonedEdit TButtonedEdit taCenter 0 bedQuantityTrucks  
    TButtonedEdit TButtonedEdit taCenter 0 bedManCostTrucks  
    TEdit TSpeedButton taRightJustify 0.00 edtRevenuesTrucks  
    TLabel TLabel   Mini-Vans:    
    TButtonedEdit TButtonedEdit taCenter 0 bedQuantityMiniVans  
    TButtonedEdit TButtonedEdit taCenter 0 bedManCostMiniVans  
    TEdit TSpeedButton taRightJustify 0.00 edtRevenuesMiniVans  
    TLabel TLabel        
    TEdit TSpeedButton taRightJustify 0.00 edtTotalRevenues  
    TBitBtn TBitBtn       bkClose
     

 

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 LearningPractical Learning: Using Images

  1. In the Tool Palette, click Win32, click TImageList and click the form
  2. Right-click the image list on the form and click ImageList Editor...
  3. Select in1.bmp, in2.bmp, Insert.bmp, out1.bmp, out2.bmp, Band.bmp, down1.bmp, and up1.bmp
     
    Image List Editor
     
    Image List Editor
  4. 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:

  • If you use only one picture, you can make the button display it at all times. This default image is represented by the ImageIndex property of the TEditButton class:
    __property int ImageIndex = 
    {
        	read=FImageIndex,
        	write=SetImageIndex
    };
  • If you use more than one picture, you can make the button display:
    • A picture when the control is not used. This is the ImageIndex image
    • A picture when the mouse is positioned on top of the button. This is represented by the HotImageIndex property:
      __property int HotImageIndex = 
      {
          	read=FHotImageIndex,
          	write=SetHotImageIndex
      };
    • A picture when the button is down while it is being clicked or if the user holds the mouse on the button. This is the role of the PressedImageIndex property:
      __property int PressedImageIndex = 
      {
      	read=FPressedImageIndex,
      	write=SetPressedImageIndex
      };
    • A picture when the button is disabled. This is done using the DisabledImageIndex proeprty:
      __property int DisabledImageIndex = 
      {
      	read=FDisabledImageIndex,
      	write=SetDisabledImageIndex
      };

Remember that the pictures are set using indexes from the list of images.

Practical LearningPractical Learning: Configuring the Left and Right Buttons

  1. On the form, click each buttoned edit control and, using the Object Inspector, set its Images to ImageList1
  2.  Click each buttoned edit control and, from the Object Inspector, change the following properties:
     
    Car Manufacture Analysis
    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
     
  3. In the lower section of the Code Editor, click Analysis.h
  4. 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
  5. 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);
    }
    //---------------------------------------------------------------------------
  6. Press F12 to display the form
  7. Double-click an unoccupied area of the form to generate its OnCreate event
  8. 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();
    }
    //---------------------------------------------------------------------------
  9. Press F12 to return to the form
  10. double-click the first buttoned edit control under Quantity to generate its OnChange event
  11. Implement the event as follows:
    //---------------------------------------------------------------------------
    void __fastcall TfrmAnalysis::bedQuantitySedanChange(TObject *Sender)
    {
    	QuantitySedan = StrToInt(this->bedQuantitySedan->Text);
    }
    //---------------------------------------------------------------------------
  12. In the top combo box of the Object Inspector, select bedQuantitySedan
  13. In the Object Inspector, click Events and double-click OnLeftButtonClick
  14. 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();
    }
    //---------------------------------------------------------------------------
  15. In the Events section of the Object Inspector, double-click OnRightButtonClick
  16. 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();
    }
    //---------------------------------------------------------------------------
  17. In the top combo box of the Object Inspector, select bedManCostSedan
  18. In the Events section of the Object Inspector, double-click OnChange
  19. Implement the event as follows:
    //---------------------------------------------------------------------------
    void __fastcall TfrmAnalysis::bedManCostSedanChange(TObject *Sender)
    {
    	ManCostSedan = StrToFloat(this->bedManCostSedan->Text);
    }
    //---------------------------------------------------------------------------
  20. In the Events section of the Object Inspector, double-click OnLeftButtonClick
  21. Implement the event as follows:
    //---------------------------------------------------------------------------
    void __fastcall TfrmAnalysis::bedManCostSedanLeftButtonClick(TObject *Sender)
    {
    	ManCostSedan--;
    
    	this->bedManCostSedan->Text = FloatToStr(ManCostSedan);
    	Calculate();
    }
    //---------------------------------------------------------------------------
  22. In the Events section of the Object Inspector, double-click OnRightButtonClick
  23. Implement the event as follows:
    //---------------------------------------------------------------------------
    void __fastcall TfrmAnalysis::bedManCostSedanRightButtonClick(TObject *Sender)
    {
    	ManCostSedan++;
    
    	this->bedManCostSedan->Text = FloatToStr(ManCostSedan);
    	Calculate();
    }
    //---------------------------------------------------------------------------
  24. In the top combo box of the Object Inspector, select bedQuantitySUV
  25. In the Events section of the Object Inspector, double-click OnChange
  26. Implement the event as follows:
    //---------------------------------------------------------------------------
    void __fastcall TfrmAnalysis::bedQuantitySUVChange(TObject *Sender)
    {
        QuantitySUV = StrToInt(this->bedQuantitySUV->Text);
    }
    //---------------------------------------------------------------------------
  27. In the Events section of the Object Inspector, double-click bedQuantityTrucks
  28. Implement the event as follows:
    //---------------------------------------------------------------------------
    void __fastcall TfrmAnalysis::bedQuantitySUVLeftButtonClick(TObject *Sender)
    {
    	QuantitySUV--;
    
    	bedQuantitySUV->Text = IntToStr(QuantitySUV);
    	Calculate();
    }
    //---------------------------------------------------------------------------
  29. In the Events section of the Object Inspector, double-click OnRightButtonClick
  30. Implement the event as follows:
    //---------------------------------------------------------------------------
    void __fastcall TfrmAnalysis::bedQuantitySUVRightButtonClick(TObject *Sender)
    {
    	QuantitySUV++;
    
    	bedQuantitySUV->Text = IntToStr(QuantitySUV);
    	Calculate();
    }
    //---------------------------------------------------------------------------
  31. In the top combo box of the Object Inspector, select bedManCostSedan
  32. In the Events section of the Object Inspector, double-click OnChange
  33. Implement the event as follows:
    //---------------------------------------------------------------------------
    void __fastcall TfrmAnalysis::bedManCostSUVChange(TObject *Sender)
    {
    	ManCostSUV = StrToFloat(this->bedManCostSUV->Text);
    }
    //---------------------------------------------------------------------------
  34. In the Events section of the Object Inspector, double-click OnLeftButtonClick
  35. 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();
    }
    //---------------------------------------------------------------------------
  36. In the Events section of the Object Inspector, double-click OnRightButtonClick
  37. 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();
    }
    //---------------------------------------------------------------------------
  38. In the top combo box of the Object Inspector, select bedQuantityTrucks
  39. In the Events section of the Object Inspector, double-click OnChange
  40. Implement the event as follows:
    //---------------------------------------------------------------------------
    void __fastcall TfrmAnalysis::bedQuantityTrucksChange(TObject *Sender)
    {
    	QuantityTrucks = StrToInt(this->bedQuantityTrucks->Text);
    }
    //---------------------------------------------------------------------------
  41. In the Events section of the Object Inspector, double-click OnLeftButtonClick
  42. 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();
    }
    //---------------------------------------------------------------------------
  43. In the Events section of the Object Inspector, double-click OnRightButtonClick
  44. 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();
    }
    //---------------------------------------------------------------------------
  45. In the top combo box of the Object Inspector, select bedManCostTrucks
  46. In the Events section of the Object Inspector, double-click OnChange
  47. Implement the event as follows:
    //---------------------------------------------------------------------------
    void __fastcall TfrmAnalysis::bedManCostTrucksChange(TObject *Sender)
    {
    	ManCostTrucks = StrToFloat(this->bedManCostTrucks->Text);
    }
    //---------------------------------------------------------------------------
  48. In the Events section of the Object Inspector, double-click OnLeftButtonClick
  49. 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();
    }
    //---------------------------------------------------------------------------
  50. In the Events section of the Object Inspector, double-click OnRightButtonClick
  51. 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();
    }
    //---------------------------------------------------------------------------
  52. In the Events section of the Object Inspector, double-click bedQuantityMiniVans
  53. Implement the event as follows:
    //---------------------------------------------------------------------------
    void __fastcall TfrmAnalysis::bedQuantityMiniVansChange(TObject *Sender)
    {
    	QuantityMiniVans = StrToInt(this->bedQuantityMiniVans->Text);
    }
    //---------------------------------------------------------------------------
  54. In the Events section of the Object Inspector, double-click OnLeftButtonClick
  55. 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();
    }
    //---------------------------------------------------------------------------
    
  56. In the Events section of the Object Inspector, double-click OnRightButtonClick
  57. 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();
    }
    //---------------------------------------------------------------------------
  58. In the top combo box of the Object Inspector, select bedManCostMiniVans
  59. In the Events section of the Object Inspector, double-click OnChange
  60. Implement the event as follows:
    //---------------------------------------------------------------------------
    void __fastcall TfrmAnalysis::bedManCostMiniVansChange(TObject *Sender)
    {
    	ManCostMiniVans = StrToFloat(this->bedManCostMiniVans->Text);
    }
    //---------------------------------------------------------------------------
  61. In the Events section of the Object Inspector, double-click OnLeftButtonClick
  62. Implement the event as follows:
    //---------------------------------------------------------------------------
    void __fastcall TfrmAnalysis::bedManCostMiniVansLeftButtonClick(TObject *Sender)
    {
    	ManCostMiniVans--;
    
    	this->bedManCostMiniVans->Text = FloatToStr(ManCostMiniVans);
    	Calculate();
    }
    //---------------------------------------------------------------------------
  63. In the Events section of the Object Inspector, double-click OnRightButtonClick
  64. Implement the event as follows:
    //---------------------------------------------------------------------------
    void __fastcall TfrmAnalysis::bedManCostMiniVansRightButtonClick(TObject *Sender)
    
    {
    	ManCostMiniVans++;
    
    	this->bedManCostMiniVans->Text = FloatToStr(ManCostMiniVans);
    	Calculate();
    }
    //---------------------------------------------------------------------------
  65. Press F9 to test the application
     
    Manufacture Car Analysis
    Manufacture Car Analysis
    Manufacture Car Analysis
  66. 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 TPopupMenu, then assign it to the DropDownMenu property of the desired button.

 
 
 

Home Copyright © 2010-2011 FunctionX, Inc.