Deding Crystal Reports (Crystal Report) has a standard report tool for Microsoft Visual Studio .NET, while upgrading to Crystal Reports for Visual Studio .NET. Its advantages are: 1. In the .NET platform, you can easily create an interactive, high-quality report content, which is the main advantage of Crystal Reports; 2. Using Crystal Reports for Visual Studio .NET, you can The Web platform and the Windows platform bearer, and the Crystal report is published on the web server as a report web service; 3. Use the WEB application created by Crystal Report to deepen the chart and filter information as needed. In .NET, the chart is actually a Crystal report that interacts with other controls in the application. Here I introduce you how to browse the crystal report in the Windows Form Application.
Design steps:
1. Software Environment: Requires the system already installed Visual Studio .NET integration development system, only the .NET Framework SDK does not implement this effect, becoming the .NET Framework SDK without a crystal report control.
2. Newly built a Visual C # item Windows application, set the text = "Crystal Report Browser", startPosition = cENTERSCREEN / / Program starts to appear in the center, and other properties remain default;
3, drag into a CrystalReportViewer from the toolbox, a button, an OpenFiledialog, to the form.
The form layout of the entire designer simply puts Button1 in the middle of the form bottom, no longer need additional layout.
Set the properties of CrystalReportViewer1 as follows:
This.CrystalReportViewer1.dock = system.windows.forms.dockstyle.Fill;
// Stop mode is full of full form
// Expand Dockpadding
this.crystalReportViewer1.dockpadding.bottom = 50;
// The bottom empty is placed in the area of Button
This.crystalReportViewer1.dockpadding.Left = 5;
This.CrystalReportViewer1.dockpadding.right = 5;
this.crystalReportViewer1.dockpadding.top = 5;
THIS.CRYSTALREPORTVIEWER1.REPORTSOURCE = NULL;
// Do not load the report resource
Set the properties of Button1 as follows:
This.Button1.Anchor = system.windows.Forms.Anchorstyles.bottom
/ / Keep fixed with the lower side of the form
This.button1.text = "Open Report";
OpenFileDialog1 is the control to open the file and set its properties as follows:
this.openfiledialog1.filter
= "Crystal Report (* .rpt) | * .RPT | All files (*. *) | *. *";
/ / Provide the file type of the open file dialog,
The default type is the type of the most defined default of this string
THIS.OpenFileDialog1.title = "Open Crystal Report";
/ / Open the title of the file dialog
The layout renderings are as follows:
4, double-click Button1, add button1_click click event:
Private void Button1_Click (Object Sender, System.Eventargs E)
{
Try
{
IF (OpenFileDialog1.Showdialog () == DialogResult.ok)
This.CrystalReportViewer1.reportsource = @ OpenFiledialog1.FileName
// Load the crystal report to bind the report file to the CrystalReportView control;
}
Catch (Exception Error)
{
MessageBox.show (Error.Tostring (), "Error");
}
}
5, ok! Press CTRL F5 to run.
You can browse the existing report instances in your system:
... / Program Files / Microsoft Visual Studio .NET / CRYSTAL Reports / Samples / Reports / Feature Examples / Chart.rpt
Using system;
Using system.drawing;
Using system.collections;
Using system.componentmodel;
Using system.windows.forms;
Using system.data;
Namespace WindowsApplication10
{
///
/// Form1 summary description.
/// summary>
Public Class Form1: System.Windows.Forms.form
{
Private crystaldecisions.windows.Forms.crystalReportViewer CrystalReportViewer1;
Private system.windows.Forms.Button button1;
Private system.windows.forms.openfiledialog openfiledialog1;
///
/// The required designer variable.
/// summary>
Private system.componentmodel.Container Components = NULL;
Public Form1 ()
{
//
// Windows Form Designer Support
//
InitializationComponent ();
//
// Todo: Add any constructor code after INITIALIZECOMPONENT call
//
}
///
/// Clean all the resources being used.
/// summary>
Protected Override Void Dispose (Bool Disposing)
{
IF (Disposing)
{
IF (Components! = NULL)
{
Components.dispose ();
}
}
Base.dispose (Disposing);
}
#Region Windows Form Designer Generated Code
///
/// Designer supports the required method - do not use the code editor to modify
/// This method is content.
/// summary>
Private vidinitiRizeComponent ()
{
This.CrystalReportViewer1 = newcrystaldecisions.windows.Forms.crystalReportViewer ();
This.button1 = new system.windows.Forms.Button ();
This.openfileDialog1 = new system.windows.Forms.openFiledialog ();
THIS.SUSPENDLAYOUT ();
//
// CrystalReportViewer1
//
This.CrystalReportViewer1.activeViewIndex = -1;
this.crystalReportViewer1.dock
= System.windows.Forms.dockStyle.Fill;
this.crystalReportViewer1.dockpadding.bottom = 50;
This.crystalReportViewer1.dockpadding.Left = 5;
This.CrystalReportViewer1.dockpadding.right = 5;
this.crystalReportViewer1.dockpadding.top = 5;
This.crystalReportViewer1.name = "CrystalReportViewer1";
THIS.CRYSTALREPORTVIEWER1.REPORTSOURCE = NULL;
This.crystalReportViewer1.size = new system.drawing.size (292, 273);
This.crystalReportViewer1.tabindex = 0;
//
// Button1
//
This.Button1.Anchor = system.windows.Forms.Anchorstyles.bottom
This.Button1.Location = new system.drawing.point (104, 240);
This.button1.name = "button1";
This.button1.tabindex = 1;
This.button1.text = "Open Report";
This.Button1.click = new system.eventhandler (this.button1_click);
//
// OpenFileDialog1
//
This.openfileDialog1.filter = "Crystal Report (* .rpt) | * .rpt | All files (*. *) | *. *";
THIS.OpenFileDialog1.title = "Open Crystal Report";
//
// Form1
//
THIS.AUTOSCALEBASESIZE = New System.drawing.size (6, 14);
THIS.CLIENTSIZE = New System.drawing.size (292, 273);
this.controls.addrange (new system.windows.forms.control] {
this.button1,
THIS.CRYSTALREPORTVIEWER1});
THIS.NAME = "Form1";
This.startPosition = system.windows.forms.formstartPosition.CenterScreen
THIS.TEXT = "Crystal Report Browser"; this.ResumeLayout (false);
}
#ndregion
///
/// The main entry point for the application.
/// summary>
[Stathread]
Static void main ()
{
Application.run (New Form1 ());
}
Private void Button1_Click (Object Sender, System.Eventargs E)
{
Try
{
IF (OpenFileDialog1.Showdialog () == DialogResult.ok)
This.CrystalReportViewer1.reportsource = @ OpenFiledialog1.FileName
/ / Load the crystal report to bind the resource report to Crystal News Viewer
}
Catch (Exception Error)
{
Messagebox.show (Error.Tostring (), "Error"); // Handling an exception error
}
}
}
}