ActiveReports for .NET 3 Online Help Request technical support
Walkthrough: Customizing the Viewer Control
See Also
User Guide > How-To Section > Walkthrough: Customizing the Viewer Control

Glossary Item Box

ActiveReports includes a control to view report output in custom preview forms. The viewer allows developers to modify the toolbars or add custom menu commands to the preview form.

Creating a basic previewer

To create a basic previewer

  1. Open a new Windows Forms project in Visual Studio and size the form according to your needs.
  2. Click the Viewer icon on the ActiveReports toolbox.

  3. Place the control on your form and set the Dock property to Fill.
  4. From the Project menu, select Add New Item.
  5. Select ActiveReports 3.0 File and click the Add button.
  6. Add the following code to the Windows Form Load event.
    'Visual Basic
    Dim rpt as new NewActiveReport1
    rpt.Run()
    Viewer1.Document = rpt.Document
    
    //C#
    ActiveReport1 rpt = new ActiveReport1();
    rpt.Run();
    viewer1.Document = rpt.Document;
  7.  Press F5 to run the report.

Using split windows on the viewer control

To use split windows on the viewer control

  1. Run your report with the viewer added by pressing F5.

  2. Drag the splitter control down.

        

  1. When the viewer is split into two sections, report layouts can be examined and report pages can be compared easily.

Adding a custom print button to the viewer control

To add a custom print button to the viewer control

  1. Add a second form to the project created above and rename 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. Add the following code to the Windows Form Load event to remove the default print button and add your own.

    ' Visual Basic
    ' Remove the default print button
    Me.Viewer1.Toolbar.Tools.RemoveAt(2)
    ' Create and add the custom button
    Dim btn As New DataDynamics.ActiveReports.Toolbar.Button()
    btn.Caption = "MyPrint"
    btn.ToolTip = "Custom Print Button"
    btn.ImageIndex = 1
    btn.ButtonStyle = DataDynamics.ActiveReports.Toolbar.ButtonStyle.TextAndIcon
    btn.Id = 333Me.Viewer1.Toolbar.Tools.Insert(2, btn)
    //C#
    // Remove the default printer button
    this.viewer1.Toolbar.Tools.RemoveAt(2);
    // Create and add the custom button
    DataDynamics.ActiveReports.Toolbar.Button btn = new DataDynamics.ActiveReports.Toolbar .Button();
    btn.Caption = "MyPrint";
    btn.ToolTip = "Custom Print Button";
    btn.ImageIndex = 1;
    btn.ButtonStyle = DataDynamics.ActiveReports.Toolbar.ButtonStyle.TextAndIcon;
    btn.Id = 333;
    this.viewer1.Toolbar.Tools.Insert(2,btn);
  5. Add the following code to the Viewer ToolClick event to display frmPrintDlg when the custom print button is clicked.
    ' Visual Basic
    ' Capture the new tool's click to show the dialog
    If e.Tool.Id = 333 Then
    Dim dlg As New frmPrintDlg()
    dlg.ShowDialog(Me)
    End If
    //C#
    // Capture the new tool's click to show the dialog
    if(e.Tool.Id == 333)
    {
    frmPrintDlg dlg = new frmPrintDlg();
    dlg.ShowDialog(this);
    }
  6. Press F5 to run the project and see the custom MyPrint button on the viewer.

See Also

©2009. All Rights Reserved.