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
- Open a new Windows Forms project in Visual Studio and size the form according to your needs.
- Click the Viewer icon on the ActiveReports toolbox.
- Place the control on your form and set the Dock property to Fill.
- From the Project menu, select Add New Item.
- Select ActiveReports 3.0 File and click the Add button.
- 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;
- Press F5 to run the report.
Using split windows on the viewer control
To use split windows on the viewer control
-
Run your report with the viewer added by pressing F5.
-
Drag the splitter control down.
-
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
- Add a second form to the project created above and rename it frmPrintDlg.
-
Add a label to frmPrintDlg and change the Text property to This is the custom print dialog.
-
Add a button to frmPrintDlg and change the Text property to OK.
-
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); - 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);
} - Press F5 to run the project and see the custom MyPrint button on the viewer.