The two most important controls offered by C1Reports to view C1Report or C1PrintDocument contents are :

  • C1PreviewPane
  • C1PrintPreviewControl

These controls offer the inbuilt ToolBar with standard Toolbar items. But many a times, there is a requirement to add Custom Buttons in this toolbar to serve a specific purpose. This blog deals with same. Follow the undermentioned steps to learn how to add Custom Button(s) in the Preview Controls' Toolbar. There are two ways to add custom toolbar items :

  • At Design Time, using 'Items' collection editor of the ToolBar property of the control
  • At Run Time, by creating an object of ToolStripButton class

C1PreviewPane :

Following are the steps to add a custom button in the toolbar at design time :

  • Drag and drop the C1PreviewPane on the form.
  • Right-click on the control and select 'AddToolBar' option. This will add the toolbars at the top of the PreviewPane.
  • Next, right-click on any of the toolbar and select 'EditItems' option.
  • 'ItemsCollectionEditor' dialog will pop-up and you will get options to add buttons, separators, etc.
  • Select the control from the left pane and set its properties in the right pane.
  • Click OK and the 'ToolStripButton' will be added in the toolbar. Double click on the newly added button and a 'ToolStripButton1_Click' method will be created that handles the 'ToolStripButton1.Click' event.

Add the following code in the Form_Load event to add a custom button at run time:

'Create a new instance of ToolStripButton  
Dim button As New ToolStripButton  
'Customize the button properties  
button.Text = "CustomButton_ViaCode"  
button.Image = ""  
'Add this button in any of the toolstrip of the PreviewControl (pagestrip in this case)  
C1PreviewPane1_pageStrip.Items.Add(button)  
'Create click event handler of the button  
AddHandler button.Click, AddressOf button_click

C1PrintPreviewControl :

Following are the steps to add a custom button in the toolbar at design time :

  • Drag and drop the C1PrintPreviewControl on the form:
  • Open the Properties window of the control.
  • Toolbars || File (or navigation, page etc) || ToolStrip || Items.
  • Click on the collection tab against the 'Items'
  • 'ItemsCollectionEditor' dialog will pop-up and you will get options to add buttons, separators, etc.
  • Select the control from the left pane and set the properties in the right pane.
  • Click OK and the 'ToolStripButton' will be added in the toolbarstrip.
  • Click on the newly added button and open it's properties window. Select the event's tab and double click on the 'Click' option.
  • The method to handle the click event of the new toostrip button will be created in the code.

Add the following code in the Form_Load event to add a custom button at run time :

'Create a new instance of ToolStripButton</p>  
Dim button As New ToolStripButton  
'Customize the button properties  
button.Text = "CustomButton_ViaCode"  
button.Image = ""  
'Add  this button in the PrintPreviewControl under any of the group (file in this case)  
C1PrintPreviewControl1.ToolBars.File.ToolStrip.Items.Add(Button)  
'Create click event handler of the button  
AddHandler button.Click, AddressOf button_click

Using the above steps, this is how the custom buttons (added via code and added via designer) would look like in the C1PrintPreviewControl, implementation is given in the attached sample. CustomButton(s) In C1PrintPreviewControl Download Sample