winform使用水晶报表的例子 - 中国WEB开发者网络 (http://www.webasp.net) -- 技术教程 (http://www.webasp.net/article/) --- winform使用水晶报表的例子 (http://www.webasp.net/article/5/4034.htm) |
| -- 作者:未知 -- 发布日期: 2003-07-12 |
| ///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> /// Summary description for Utils. /// </summary> 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; } } } |
| webasp.net |