Examples of WinForm using Crystal Reports

Source: Internet
Author: User
Crystal Report///form File
Namespace Simpleapp
{
Using System;
Using System.Drawing;
Using System.Collections;
Using System.ComponentModel;
Using System.WinForms;
Using System.Data;

public class SimpleForm:System.WinForms.Form
{
Private System.ComponentModel.Container components;
Private System.WinForms.Button Btnselectreport;
Private SeagateSoftware.WinForms.CrystalReportViewer CrystalReportViewer1;

Public Simpleform ()
{
//
Required for Win Form Designer support
//
InitializeComponent ();
Enableviewer (FALSE);
}

public override void Dispose ()
{
Base. Dispose ();
Components. Dispose ();
}

private void InitializeComponent ()
{
this.components = new System.ComponentModel.Container ();
This.crystalreportviewer1 = new SeagateSoftware.WinForms.CrystalReportViewer ();
This.btnselectreport = new System.WinForms.Button ();

This. AutoScaleBaseSize = new System.Drawing.Size (5, 13);
This. Text = "Viewing a Crystal";
This. StartPosition = System.WinForms.FormStartPosition.CenterScreen;
@design this. TrayLargeIcon = false;
@design this. trayheight = 0;
This. ClientSize = new System.Drawing.Size (664, 509);

Crystalreportviewer1.location = new System.Drawing.Point (8, 40);
Crystalreportviewer1.size = new System.Drawing.Size (648, 464);
Crystalreportviewer1.activeviewindex =-1;
Crystalreportviewer1.selectionformula = "";
Crystalreportviewer1.displaytoolbar = true;
Crystalreportviewer1.displaygrouptree = true;
Crystalreportviewer1.tabindex = 2;
Crystalreportviewer1.anchor = System.WinForms.AnchorStyles.All;
Crystalreportviewer1.displaybackgroundedge = false;

Btnselectreport.location = new System.Drawing.Point (8, 8);
Btnselectreport.size = new System.Drawing.Size (96, 24);
Btnselectreport.tabindex = 1;
Btnselectreport.font = new System.Drawing.Font ("Arial", 8f, System.Drawing.FontStyle.Bold);
Btnselectreport.text = "Select the";
Btnselectreport.click + = new System.EventHandler (Btnselectreport_click);

This. Controls.Add (Btnselectreport);
This. Controls.Add (CrystalReportViewer1);

}
protected void Btnselectreport_click (object sender, System.EventArgs e)
{
Get a RPT file to display in the Crystal the viewer
OpenFileDialog Openfiledlg = new OpenFileDialog ();
Openfiledlg.initialdirectory = Utils.getsamplereportsdir ();
Openfiledlg.filter = "Crystal Reports (*.rpt) |*.rpt| All Files (*.*) |*.* ";
if (openfiledlg.showdialog () = = DialogResult.OK)
{
Set the ReportName property
Crystalreportviewer1.reportname = Openfiledlg.filename;
Enableviewer (TRUE);
}
}

This function enables and disables the Crystal Reports Win Form Viewer
private void Enableviewer (bool show)
{
SeagateSoftware.WinForms.ToolbarStateChangeEvent evt = new SeagateSoftware.WinForms.ToolbarStateChangeEvent (show);
CrystalReportViewer1.Toolbar.OnStateChange (this, evt);
}
/*
* The main entry point for the application.
*
*/
public static void Main (string[] args)
{
Application.Run (New Simpleform ());
}
}
}

Util.cs
Namespace Simpleapp
{
Using System;
Using Microsoft.Win32;

<summary>
Summary description for Utils.
</summary>
public class Utils
{
public static string Getsamplereportsdir ()
{
Get the path VS. Is installed to
RegistryKey RegKey = registry.localmachine;
RegKey = Regkey.opensubkey ("Software\\microsoft\\visualstudio\\7.0\\setup\\vs");
String dir = Regkey.getvalue ("Productdir"). ToString ();
dir = = "Crystal reports\\samples\\reports\\";
return dir;
}
}
}


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.