Skip to main content

DevExpress v24.2 Update — Your Feedback Matters

Our What's New in v24.2 webpage includes product-specific surveys. Your response to our survey questions will help us measure product satisfaction for features released in this major update and help us refine our plans for our next major release.

Take the survey Not interested

Add Button to Print Preview Standard Toolbar

  • 2 minutes to read

This help topic demonstrates how to add a new command button to Print Preview standard toolbar.

#Prerequisites

Create a WinForms project, add the DocumentViewer control to a form, add a new report to the project. Review the forllowing topic for more information: Create a Report in Visual Studio.

Generate the DocumentViewer standard toolbar. To do this, click the DocumentViewer smart tag and select Create Standard Toolbar.

Add Standard Toolbar to WinForms Preview

#Add a Custom Button

  1. Click the [Add] button in the Print Bar Manager menu and add a new button to the menu.

    Add Button to Standard Toolbar in WinForms Preview

  2. Change the button caption to Edit and set the BarItem.Hint property to Edit the report:

    Specify Button Hint in the Standard Toolbar in WinForms Preview

  3. Move the **Edit ** button from the menu to the toolbar:

    Move Button From Menu to Toolbar

  4. Handle the button’s BarItem.ItemClick event, and add the following code snippet that opens the current report in End-User Report Designer:

    using DevExpress.XtraReports.UI;
    // ...
    
    private void barButtonItem1_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) {
        var report = (XtraReport)Activator.CreateInstance((Type)this.documentViewer1.DocumentSource);
        ReportDesignTool designTool = new ReportDesignTool(report);
        designTool.ShowDesignerDialog();
    }
    

Note

This code snippet does not update the document displayed in Print Preview after the report in the Report Designer is changed. Review the following help topic for more information on Print Preview commands: Print Preview Commands - Execute, Override, Hide.

The following image shows the application after a user clicks a custom button:

Custom Button in a Print Preview Standard Toolbar - Result