Glossary Item Box

Samples | Walkthroughs

See Also ActiveReports for .NET 2 Online Help Send feedback to Data Dynamics

Walkthrough: Customizing the Viewer Control

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

This walkthrough illustrates how to add and customize the ActiveReports viewer control to your report.

This walkthrough is split up into the following activities:

To complete the walkthrough, you must have the ActiveReports controls added to your Visual Studio toolbox. For more information, see Adding ActiveReports Controls to the Visual Studio Toolbox.

Creating a custom preview screen in a report

To create a custom preview screen in a report

  1. Open an ActiveReport in Visual Studio.
  2. Add a Form to your project..
  3. Click on the Viewer icon on the ActiveReports toolbox.

       

  1. Place the control on your form and size it according to your needs.
  2. Set the Dock property to Fill.
  3. Add the following code to the Form1_Load event.
    ' Visual Basic
    Dim rpt as new ActiveReport1
    Viewer1.Document = rpt.Document
    rpt.Run()
    //C#
    ActiveReport1 rpt = new ActiveReport1();
    viewer1.Document = rpt.Document;
    rpt.Run(); 
  4.  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 button to the viewer control

To add a button to the viewer control

  1. Open an ActiveReport in Visual Studio.

  2. Add a form to your project.

  3. Set up the ActiveReports viewer on Form1 following the steps outlined above.

  4. Add a second form to your project and rename it frmPrintDlg.

  5. Add a label to frmPrintDlg and change the Text property to "This is the custom print dialog."

  6. Add a button to frmPrintDlg and change the Text property to "OK". Please note that for the image to show properly, it should be in bitmap format and should have the mask color set to System.Drawing.Color.Magenta. (This button is for appearance only in this walkthrough.)

  7. Add the following code to the Form1_Load event.

    ' 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);
  8. Add the following code to the Viewer1_ToolClick event.
    ' 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);
    }

Samples | Walkthroughs

 

 


Copyright © 2004-2005 Data Dynamics, Ltd. All rights reserved.