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 crystalReportViewer1 following properties: this.crystalReportViewer1.Dock = System.Windows.Forms.DockStyle.Fill; // stop mode to expand to fill the entire window @ DockPaddingthis.crystalReportViewer1.DockPadding.Bottom = 50; // bottom vacated Button placement region this.crystalReportViewer1.DockPadding.Left = 5; this.crystalReportViewer1.DockPadding.Right = 5; this.crystalReportViewer1.DockPadding.Top = 5; this.crystalReportViewer1.ReportSource = null; // to not report resource loading Set the properties of Button1 as follows:
This.Button1.Anchor = system.windows.Forms.Anchorstyles.bottom; / / Keeping this with the form of 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 this string Top of the most defined type this.openfiledialog1.title = "Open Crystal Report"; // Open the title of the file dialog
FIG layout effects 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, 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 {///
/// summary> private void InitializeComponent () {this.crystalReportViewer1 = new CrystalDecisions.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.tabind EX = 1; this.button1.text = "Open Report"; this.Button1.Click = new system.EventHandler (this.button1_click); //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////> .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); this .Name = "form1"; this.startPosition = system.windows.forms.formstartPosition.centerscreen; this.text = "Crystal Report Browser";