TIEImageEnGlobalSettings.OnAddCustomToolbarButton
Declaration
property OnAddCustomToolbarButton: TIEAddCustomButtonEvent;
Description
Event used to add extra buttons to toolbars, such as the
automatic toolbars of TImageEnView.
This event is called for each button that is added to the toolbar, allowing you to position your new button(s) before a
specific button.
To add an extra button set
AddButton and specify the properties of the button.
Value | Description |
Sender | The toolbar |
BeforeButtonID | Specifies the ID of a button being added. Your custom button will be positioned to the left of this button. 0: Specifies the very left of the toolbar. -1 specifies the very right of the toolbar |
AddButton | Set to true if you are adding a button at this position |
BtnID | Your own ID to recognize this button. It should be IECustom_Button_ID + n |
BtnCaption | A caption for the button. This is only used if ShowCaptions is true |
BtnHint | A hover hint for the button |
BtnImgID | Specify one of the Toolbar Button Image Consts. If you need to customize the buttons, use OnAddToolbarButtonImage |
To enable or disable the button use the
OnToolbarButtonUpdate event.
To handle the clicking of the button use the
OnToolbarButtonExecute event.
Note: Ensure you reset this event before destroying your form, e.g. IEGlobalSettings().OnAddCustomToolbarButton := nil;
Example
IEGlobalSettings().OnToolbarButtonExecute := Form1CustomButtonExecute;
IEGlobalSettings().OnToolbarButtonUpdate := Form1CustomButtonUpdate;
IEGlobalSettings().OnAddCustomToolbarButton := Form1AddCustomToolbarButton;
// Add a custom open button, and two other buttons to the right side of the toolbar
const
MY_HOME_BUTTON_ID = IECustom_Button_ID + 1;
MY_IMAGEINFO_BUTTON_ID = IECustom_Button_ID + 2;
MY_LOADRECENT_BUTTON_ID = IECustom_Button_ID + 3;
procedure TMainForm.Form1CustomButtonExecute(Sender: TObject; ButtonID: Integer; var Handled: Boolean);
begin
// Button Clicked
case ButtonID of
MY_HOME_BUTTON_ID : ShellExecute(Handle, nil, PChar('http://www.imageen.com'), nil, nil, SW_SHOWNORMAL);
MY_IMAGEINFO_BUTTON_ID : ShowMessage( Format( 'Image Size: %d x %d', [ ImageEnView1.IEBitmap.Width, ImageEnView1.IEBitmap.Height ]));
MY_LOADRECENT_BUTTON_ID : ImageEnView1.IO.LoadFromFile( fLastUsedFile );
end;
end;
procedure TMainForm.Form1CustomButtonUpdate(Sender: TObject; ButtonID:
Integer; var Handled: Boolean);
begin
// Set status of button
case ButtonID of
MY_IMAGEINFO_BUTTON_ID : TControl( Sender ).Enabled := not ImageEnView1.IsEmpty;
MY_LOADRECENT_BUTTON_ID : TControl( Sender ).Enabled := fLastUsedFile <> '';
end;
end;
procedure TMainForm.Form1AddCustomToolbarButton(Sender: TObject;
BeforeButtonID: Integer; var AddButton: Boolean; var BtnID: Integer; var
BtnCaption, BtnHint: string; var BtnImgID: Integer);
begin
if BeforeButtonID = -1 then // Right-side of toolbar
begin
AddButton := True;
BtnID := MY_HOME_BUTTON_ID;
BtnCaption := 'Home'; // Not usually used
BtnHint := 'Visit www.imageEn.com';
BtnImgID := ITBRES_HOMEOUTLINE_24;
end
else
if BeforeButtonID = MY_HOME_BUTTON_ID then // To Left of MY_HOME_BUTTON_ID
begin
AddButton := True;
BtnID := MY_IMAGEINFO_BUTTON_ID;
BtnCaption := 'About'; // Not usually used
BtnHint := 'About this Image';
BtnImgID := ITBRES_INFORMATIONOUTLINE_24;
end
else
if BeforeButtonID = IEViewSave_Button_ID then // To Left of "Save" button (after open)
begin
AddButton := True;
BtnID := MY_LOADRECENT_BUTTON_ID;
BtnCaption := 'Open Last File'; // Not usually used
BtnHint := 'Open Last File';
BtnImgID := ITBRES_FOLDERIMAGE_24;
end;
end;
See Also
-
OnAddCustomPopupMenuItem-
OnAddCustomButton