TButtonedEdit (C++)
Description
This example shows how to use the TButtonedEdit class. This example implements a component like "TButtonedEdit search", that can be found in the tool palette window. Entering the control enables the right button; the left button displays a MessageDlg and the right button clears the input text.
Code
__fastcall TForm4::TForm4(TComponent* Owner)
: TForm(Owner)
{
//Declaring an instance
btnEdit = new TButtonedEdit(this);
//Setting the parent so that it will autodelete
btnEdit->Parent = this;
//Positioning
btnEdit->Left = 10;
btnEdit->Top = 10;
//Creating a TImageList and using it for the button
TImageList* imList = new TImageList(this);
Graphics::TBitmap* bmap = new Graphics::TBitmap();
bmap->LoadFromFile("..\\littleB_16.bmp");
imList->Add(bmap,NULL);
bmap->LoadFromFile("..\\little_logo_16.bmp");
imList->Add(bmap,NULL);
btnEdit->Images = imList;
//Selecting the image for the left button and enabling it
btnEdit->LeftButton->Visible = true;
btnEdit->LeftButton->Enabled = true;
btnEdit->LeftButton->ImageIndex = 0;
btnEdit->LeftButton->DisabledImageIndex = 0;
btnEdit->LeftButton->PressedImageIndex = 0;
btnEdit->LeftButton->HotImageIndex = 0;
//Selecting the image for the right button
//This will be enabled when the content changes.
btnEdit->RightButton->Enabled = true;
btnEdit->RightButton->ImageIndex = 1;
btnEdit->RightButton->DisabledImageIndex = 1;
btnEdit->RightButton->PressedImageIndex = 1;
btnEdit->RightButton->HotImageIndex = 1;
//Selecting an action for the buttoned edit
btnEdit->OnEnter = btnEditEnter;
btnEdit->OnRightButtonClick = btnEditRightClick;
btnEdit->OnLeftButtonClick = btnEditLeftClick;
//Default text in the edit
btnEdit->Text = "Default";
btnEdit->Constraints->MinHeight = 16;
btnEdit->Height = 16;
//Finally, displaying the button
btnEdit->Show();
}
void __fastcall TForm4::btnEditEnter(TObject* Sender){
btnEdit->Text = "";
btnEdit->RightButton->Visible = true;
}
void __fastcall TForm4::btnEditRightClick(TObject* Sender){
//Resetting to default state
btnEdit->Text = "Default";
btnEdit->RightButton->Visible = false;
}
void __fastcall TForm4::btnEditLeftClick(TObject* Sender){
MessageDlg("Left button pressed with: " + btnEdit->Text,
mtInformation, TMsgDlgButtons() << mbOK, 0);
}
Uses
- Vcl.ExtCtrls.TButtonedEdit ( fr | de | ja )
- Vcl.ExtCtrls.TEditButton ( fr | de | ja )
- Vcl.ExtCtrls.TCustomButtonedEdit.LeftButton ( fr | de | ja )
- Vcl.ExtCtrls.TCustomButtonedEdit.RightButton ( fr | de | ja )
- Vcl.ExtCtrls.TCustomButtonedEdit.Images ( fr | de | ja )
- Vcl.ExtCtrls.TCustomButtonedEdit.OnLeftButtonClick ( fr | de | ja )
- Vcl.ExtCtrls.TCustomButtonedEdit.OnRightButtonClick ( fr | de | ja )
- Vcl.ExtCtrls.TEditButton.Enabled ( fr | de | ja )
- Vcl.ExtCtrls.TEditButton.ImageIndex ( fr | de | ja )
- Vcl.ExtCtrls.TEditButton.DisabledImageIndex ( fr | de | ja )
- Vcl.ExtCtrls.TEditButton.PressedImageIndex ( fr | de | ja )
- Vcl.ExtCtrls.TEditButton.HotImageIndex ( fr | de | ja )