繁体中文
设为首页
加入收藏
当前位置:.Net技术首页 >> 报表/图形/Office >> winform使用水晶报表的例子

winform使用水晶报表的例子

2004-10-01 08:26:10  作者:  来源:互联网  浏览次数:30  文字大小:【】【】【
简介:///Form文件 namespace SimpleApp { using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.WinForms; using System.Data; public class SimpleForm : Sy...

///Form文件

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 Report";

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 Report";

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 report 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 description for Utils.

///

public class Utils

{

public static string GetSampleReportsDir()

{

// Get the path VS was 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;

}

}

}

责任编辑:admin
相关文章