ActiveReports 13
Customize the Viewer Control
ActiveReports 13 > ActiveReports User Guide > Viewing Reports > Windows Forms > Customize the Viewer Control

ActiveReports includes a Viewer control for Windows Forms that lets you show report output in a custom preview form. You can modify both viewer's mouse mode and touch mode toolbars and set custom commands. For example, in the following sample codes we show customization specific to mouse mode toolbar and touch mode toolbar.

To create a basic preview form

  1. In Visual Studio, create a new Windows Forms project.
  2. From the Visual Studio toolbox on the ActiveReports 13 tab, drag the Viewer control onto the form. If you do not have the Viewer in your toolbox, see Adding ActiveReports Controls.
  3. With the viewer control selected, in the Properties window, set the Dock property to Fill.
  4. From the Project menu, select Add New Item.
  5. Select ActiveReports 13 Section Report (code-based) and click the Add button.
  6. Double-click in the title bar of the form to create a Form Load event.
  7. Add the following code to run the report and display the resulting document in the viewer.

    To write the code in Visual Basic.NET

    Visual Basic.NET code. Paste INSIDE the Form Load event.
    Copy Code
    Dim rpt as new SectionReport1
    Viewer1.LoadDocument(rpt)
    

    To write the code in C#

    C# code. Paste INSIDE the Form Load event.
    Copy Code
    SectionReport1 rpt = new SectionReport1();
    viewer1.LoadDocument(rpt);
    
  8. Press F5 to run the project.

Customize the Mouse Mode Toolbar

  1. Add a second Windows Form to the project created above and name it frmPrintDlg.
  2. Add a label to frmPrintDlg and change the Text property to This is the custom print dialog.
  3. Add a button to frmPrintDlg and change the Text property to OK.
  4. Back on the viewer form, double-click the title bar of the form to go to the Form Load event.
  5. Add the following code to the Form Load event to remove the default print button and add your own.

    To write the code in Visual Basic.NET

    Visual Basic.NET code. Paste INSIDE the Form Load event.
    Copy Code
    'Remove the print button.
    Viewer1.Toolbar.ToolStrip.Items.RemoveAt(2)
    'Remove the extra separator.
    Viewer1.Toolbar.ToolStrip.Items.RemoveAt(1)
    'Add a new button to the end of the tool strip with the caption "Print."
    Dim tsbPrint As New ToolStripButton("Print")
    Viewer1.Toolbar.ToolStrip.Items.Add(tsbPrint)
    'Create a click event handler for the button.
    AddHandler tsbPrint.Click, AddressOf tsbPrint_Click
    

    To write the code in C#

    C# code. Paste INSIDE the Form Load event.
    Copy Code
    //Remove the print button. 
    viewer1.Toolbar.ToolStrip.Items.RemoveAt(2);
    //Remove the extra separator.
    viewer1.Toolbar.ToolStrip.Items.RemoveAt(1);
    //Add a new button to the end of the tool strip with the caption "Print."
    ToolStripButton tsbPrint = new ToolStripButton("Print");
    viewer1.Toolbar.ToolStrip.Items.Add(tsbPrint);
    //Create a click event handler for the button.
    tsbPrint.Click += new EventHandler(tsbPrint_Click);
    
  6. Add the following code to the Form class below the Load event to display frmPrintDlg when a user clicks the custom print button.

    To write the code in Visual Basic.NET

    Visual Basic.NET code. Paste BELOW the Form Load event.
    Copy Code
    'Call the custom dialog from the new button's click event.
    Private Sub tsbPrint_Click(sender As Object, e As EventArgs)
        Me.CustomPrint()
    End Sub
    
    'Call the custom print dialog.
    Private Sub CustomPrint()
        Dim _printForm As New frmPrintDlg()
        _printForm.ShowDialog(Me)
    End Sub
    

    To write the code in C#

    C# code. Paste BELOW the Form Load event.
    Copy Code
    //Call the custom dialog from the new button's click event.
    private void tsbPrint_Click(object sender, EventArgs e)
    {
        this.CustomPrint();
    }
    
    //Call the custom print dialog.
    private void CustomPrint()
    {
        frmPrintDlg _printForm = new frmPrintDlg();
        _printForm.ShowDialog(this);
    }
    
  7. Press F5 to run the project and click on the print button of main viewer to view custom print dialog.

Customize the Touch Mode Toolbar

  1. Double-click in the title bar of the Viewer form to create a Form Load event.
  2. Add the following code to add a custom Zoom out button.

    To write the code in Visual Basic.NET

    Visual Basic.NET code. Paste INSIDE the Form Load event.
    Copy Code
    Dim zoomOutButton = viewer1.TouchModeToolbar.ToolStrip.Items(8)
    zoomOutButton.Visible = true
    

    To write the code in C#

    C# code. Paste INSIDE the Form Load event.
    Copy Code
    var zoomOutButton = viewer1.TouchModeToolbar.ToolStrip.Items[8];
    zoomOutButton.Visible = true;
    

Caution: Any customization done in mouse mode does not apply to the touch mode and vice versa.

Although this topic and the sample both demonstrate using section reports, customized viewers support page reports and RDL reports as well. The only difference is in the way that you load reports. For more information, see Windows Forms Viewer.

See Also