⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 frmviewer.cs

📁 简单CRYSTAL REPORT程序,自己也是刚刚下来看有很多不明白的地方,仅供参考,一起学习
💻 CS
字号:
//********************************************
//
//File Name:     	ViewerEvents.sln
//Created:       	May 17, 2002
//Author ID:     	HAN
//Purpose:       	The C# .NET sample Windows application 
//                   demonstrates how to capture events from the 
//                   Windows Form Viewer object.
//
//********************************************


using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;

namespace csharp_win_viewer_events
{
	/// <summary>
	/// Summary description for frmViewer.
	/// </summary>
	public class frmViewer : System.Windows.Forms.Form
	{

		NorthwindSample crReportDocument=new NorthwindSample();

		private CrystalDecisions.Windows.Forms.CrystalReportViewer crystalReportViewer1;
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;

		public frmViewer()
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();

			//
			// TODO: Add any constructor code after InitializeComponent call
			//

			crystalReportViewer1.ReportSource = crReportDocument;

	
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{

		
			this.crystalReportViewer1 = new CrystalDecisions.Windows.Forms.CrystalReportViewer();
			
			//add event handlers to the report viewer
			this.crystalReportViewer1.HandleException += new CrystalDecisions.Windows.Forms.ExceptionEventHandler(this.CrystalReportViewer1_HandleException);
			this.crystalReportViewer1.Navigate += new CrystalDecisions.Windows.Forms.NavigateEventHandler(this.CrystalReportViewer1_Navigate);
			this.crystalReportViewer1.ReportRefresh += new CrystalDecisions.Windows.Forms.RefreshEventHandler(this.CrystalReportViewer1_Refresh);
			this.crystalReportViewer1.DrillDownSubreport += new CrystalDecisions.Windows.Forms.DrillSubreportEventHandler(this.CrystalReportViewer1_DrillDownSubreport);
			this.crystalReportViewer1.Drill +=new CrystalDecisions.Windows.Forms.DrillEventHandler(this.CrystalReportViewer1_DrillDown);	
			this.crystalReportViewer1.Search += new CrystalDecisions.Windows.Forms.SearchEventHandler(this.CrystalReportViewer1_Search);
			this.crystalReportViewer1.ViewZoom += new CrystalDecisions.Windows.Forms.ZoomEventHandler(this.CrystalReportViewer1_ViewZoom);


			this.SuspendLayout();
			// 
			// crystalReportViewer1
			// 
			this.crystalReportViewer1.ActiveViewIndex = -1;
			this.crystalReportViewer1.Dock = System.Windows.Forms.DockStyle.Fill;
			this.crystalReportViewer1.Name = "crystalReportViewer1";
			this.crystalReportViewer1.ReportSource = null;
			this.crystalReportViewer1.Size = new System.Drawing.Size(292, 273);
			this.crystalReportViewer1.TabIndex = 0;
			// 
			// frmViewer
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(292, 273);
			this.Controls.AddRange(new System.Windows.Forms.Control[] {
																		  this.crystalReportViewer1});
			this.Name = "frmViewer";
			this.Text = "frmViewer";
			this.ResumeLayout(false);

		}
		#endregion

		private void CrystalReportViewer1_Refresh(Object sourece, CrystalDecisions.Windows.Forms.ViewerEventArgs e)
		{
			//this event will tell you when the report is refreshed.
			MessageBox.Show("The Data will be refreshed.", "Request new data", MessageBoxButtons.OK, MessageBoxIcon.Information);
		}

		private void CrystalReportViewer1_Navigate(Object sourece, CrystalDecisions.Windows.Forms.NavigateEventArgs e)
		{
			
			//this event will message box the page that you're on
			if (e.NewPageNumber != 1)
				MessageBox.Show("You're on page number " + e.NewPageNumber, "Page Number", MessageBoxButtons.OK, MessageBoxIcon.Information);
		
		}
		
		private void CrystalReportViewer1_HandleException(Object sourece, CrystalDecisions.Windows.Forms.ExceptionEventArgs e)
		{
			//this event can be usefull for error handling. It will fire when there's
			//any error with running the report
			Exception err; 
			err = e.Exception;
			MessageBox.Show(" This is a message to demonstrate the HandleException Event of the Crystal Reports Viewer Control. The following lines describe the error." + "\n" + "\n" + err.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
		}

		private void CrystalReportViewer1_DrillDownSubreport(Object sourece, CrystalDecisions.Windows.Forms.DrillSubreportEventArgs e)		
		{
			//this will bring up a messagebox that tells you the name of your subreports
			//as the appear on the main report.
			MessageBox.Show("You have clicked on a subreport named " + e.NewSubreportName, "Click on Subreport", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1);

		}
		
		private void CrystalReportViewer1_DrillDown(Object sourece, CrystalDecisions.Windows.Forms.DrillEventArgs e)		
		{
			//this event will fire when user drills down on any group and will give
			//you the group name.
			MessageBox.Show("You are drilling down on group " + e.NewGroupName, "Drilling down", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1);

		}


		private void CrystalReportViewer1_Search(Object source, CrystalDecisions.Windows.Forms.SearchEventArgs e)
		{	
			//this event will tell you the text of what you have searched for.
			MessageBox.Show("You have searched for " + e.TextToSearch, "Searched for", MessageBoxButtons.OK, MessageBoxIcon.Information);
		}

		private void CrystalReportViewer1_ViewZoom(Object source, CrystalDecisions.Windows.Forms.ZoomEventArgs e)
		{
			//this event will tell you what zoom level you've chosen
			if (e.NewZoomFactor != 100) 
			{
				if (e.NewZoomFactor == 1)
				{
					MessageBox.Show("You have chosen Page Width for your zoom level.", "Zoom level", MessageBoxButtons.OK, MessageBoxIcon.Information);
					return;
				}

				if (e.NewZoomFactor == 2)
				{
					MessageBox.Show("This report is best viewed at 100%. You have chosen Whole Page for your Zoom level.", "Zoom level", MessageBoxButtons.OK, MessageBoxIcon.Information);
					return;
				}
				MessageBox.Show("This report is best viewed at 100%. You have chosen " + e.NewZoomFactor.ToString() + " %", "Zoom level", MessageBoxButtons.OK, MessageBoxIcon.Information);
									
			}
		}
	}
}






⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -