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);
}
}
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;
}
}
}
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.