Question
“How do I add a custom button to the preview toolbar?”
Solution
Create a Preview Plugin that overrides the CreateToolbarItems routine. Use the Toolbar.AddButton routine to add a new button to the toolbar before the default buttons are created. Take a look at the TppPreview.CreateToolbarItems routine located in the ppPreview.pas file for examples of how the existing buttons are created.
Download: AddButtonToPreview.zip
Sample Delphi code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
uses ppPreview, ppTBX, ppToolResources, Dialogs; type TmyPreview = class(TppPreview) private FNewButton: TppTBXItem; protected procedure CreateToolbarItems; override; public procedure ehFilebutton_Click(Sender: TObject); property NewButton: TppTBXItem read FFileButton; end; implementation {------------------------------------------------------------------------------} { TmyPreview.CreateToolbarItems} procedure TmyPreview.CreateToolbarItems; begin Toolbar.BeginUpdate; FNewButton := Toolbar.AddButton(); //FNewButton.Images := //Add image list here FNewButton.ImageIndex := ToolImageList.AddTool('PPNEW'); //Index of image in ImageList FNewButton.OnClick := ehFilebutton_Click; Toolbar.EndUpdate; inherited; end; procedure TmyPreview.ehFilebutton_Click(Sender: TObject); begin ShowMessage('New Button'); end; {****************************************************************************** * ** I N I T I A L I Z A T I O N / F I N A L I Z A T I O N * {******************************************************************************} initialization TppPreviewPlugIn.Register(TmyPreview); finalization TppPreviewPlugIn.UnRegister(TmyPreview); end. |