Glossary Item Box
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.
To create a custom preview screen in a report
' Visual Basic
Dim rpt as new ActiveReport1
Viewer1.Document = rpt.Document
rpt.Run()
//C#
ActiveReport1 rpt = new ActiveReport1();
viewer1.Document = rpt.Document;
rpt.Run();
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.
To add a button to the viewer control
Open an ActiveReport in Visual Studio.
Add a form to your project.
Set up the ActiveReports viewer on Form1 following the steps outlined above.
Add a second form to your project 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". 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.)
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);
' 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);
}
See Also |
Copyright © 2004-2005 Data Dynamics, Ltd. All rights reserved.