ActiveReports Developer 7 > ActiveReports Developer Guide > How To > Customize, Localize, and Deploy > Customize the Viewer Control |
ActiveReports Developer includes a Viewer control for Windows Forms that lets you show report output in a custom preview form. You can modify the viewer toolbar and set custom commands. For example, in the following sample code we remove the Print button and add a new Print button that calls a custom dialog.
To create a basic preview form
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); |
To add a custom print button to the viewer control
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.MainBar.Items.RemoveAt(2) 'Remove the extra separator. Viewer1.Toolbar.MainBar.Items.RemoveAt(1) 'Add a new button to the end of the main bar with the caption "Print." Dim tsbPrint As New ToolStripButton("Print") Viewer1.Toolbar.MainBar.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.MainBar.Items.RemoveAt(2); //Remove the extra separator. viewer1.Toolbar.MainBar.Items.RemoveAt(1); //Add a new button to the end of the main bar with the caption "Print." ToolStripButton tsbPrint = new ToolStripButton("Print"); viewer1.Toolbar.MainBar.Items.Add(tsbPrint); //Create a click event handler for the button. tsbPrint.Click += new EventHandler(tsbPrint_Click); |
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); } |
You can also remove any of the other buttons from the three toolbars: MainBar, MouseModeBar, and NavigationBar. For this example, we only added a button with text, but you can also add an icon or an icon plus text. You can see custom icons, custom menus, and more in the included Custom Preview sample that is located in ...\Documents\ComponentOne Samples\ActiveReports Developer 7\Section Reports\C#\CustomPreview.
Although this topic and the sample both demonstrate using section reports, customized viewers support page reports as well. The only difference is in the way that you load reports. For more information, see Using the Viewer.