麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > 學院 > 開發設計 > 正文

VC# .Net中使用Crystal Report

2019-11-18 19:43:12
字體:
來源:轉載
供稿:網友

  大名鼎鼎的 Crystal Reports(水晶報表)已內嵌為微軟 Visual Studio .NET的標準報表工具,同時升級到 Crystal Reports for Visual Studio .NET。它的優點是:1、在 .NET 平臺能夠輕松創建交互式的、高質量顯現的報表內容,這也是 Crystal Reports 長期以來所具有的主要優勢;2、使用 Crystal Reports for Visual Studio .NET,可以在 Web 平臺和 Windows 平臺上承載報表,并將 Crystal 報表作為報表 Web 服務在 Web 服務器上發布;3、利用Crystal Report 創建的Web應用程序,使用戶可以深化圖表并根據需要篩選信息。在 .NET 中,圖表實際上就是一個與應用程序中其他控件進行交互的 Crystal 報表。在這里我向大家介紹如何在 Windows 窗體應用程序中瀏覽水晶報表。

  設計步驟:

  1、軟件環境:要求系統已安裝Visual Studio .Net 集成開發系統,僅裝有 .Net Framework SDk 不能實現本例效果,成為 .Net Framework SDK 沒有水晶報表控件。

  2、新建一個 Visual C# 項目 Windows 應用程序,設置Form1的Text="水晶報表瀏覽器",StartPosition=CenterScreen //程序開始出現在屏幕中央,其它屬性均保持默認;

  3、從工具箱拖入一個CrystalReportViewer,一個Button,一個openFileDialog,到窗體。

  整個設計器的窗體布局只需將button1置于窗體底邊中部,不再需要其它多余布局。

  設置crystalReportViewer1的屬性如下:

this.crystalReportViewer1.Dock = System.Windows.Forms.DockStyle.Fill;
//??糠绞綖槌錆M整個窗體
//展開+DockPadding
this.crystalReportViewer1.DockPadding.Bottom = 50;
//底部空出放置Button的區域
this.crystalReportViewer1.DockPadding.Left = 5;
this.crystalReportViewer1.DockPadding.Right = 5;
this.crystalReportViewer1.DockPadding.Top = 5;
this.crystalReportViewer1.ReportSource = null;
//先不載入報表資源

  設置button1的屬性如下:

this.button1.Anchor = System.Windows.Forms.AnchorStyles.Bottom;
//與窗體的下邊保持固定
this.button1.Text = "打開報表";
openFileDialog1是打開文件的控件,設置其屬性如下:
this.openFileDialog1.Filter
= "Crystal Report (*.rpt)|*.rpt|所有文件(*.*)|*.*";
//提供打開文件對話框的文件類型,
默認類型就是此字符串的最前一種定義的類型
this.openFileDialog1.Title = "打開水晶報表";
//打開文件對話框的標題 

  布局效果圖如下:

  4、雙擊button1,添加button1_Click點擊事件:

PRivate void button1_Click(object sender, System.EventArgs e)
{
 try
 {
  if(openFileDialog1.ShowDialog()==DialogResult.OK)
   this.crystalReportViewer1.ReportSource = @openFileDialog1.FileName;
   //加載水晶報表,將報表文件綁定到CrystalReportView 控件;
 }
 catch(Exception error)
 {
  MessageBox.Show(error.ToString(),"錯誤");
 }

  5、OK!按Ctrl+F5運行吧。

  可以瀏覽你系統內現有的報表實例:

.../Program Files/Microsoft Visual Studio .NET/Crystal Reports/Samples/Reports/Feature Examples/Chart.rpt

 

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace Windowsapplication10
{
 /// <summary>
 /// Form1 的摘要說明。
 /// </summary>
 public class Form1 : System.Windows.Forms.Form
 {
  private CrystalDecisions.Windows.Forms.CrystalReportViewer crystalReportViewer1;
  private System.Windows.Forms.Button button1;
  private System.Windows.Forms.OpenFileDialog openFileDialog1;
  /// <summary>
  /// 必需的設計器變量。
  /// </summary>
  private System.ComponentModel.Container components = null;
  public Form1()
  {
   //
   // Windows 窗體設計器支持所必需的
   //
   InitializeComponent();
   //
   // TODO: 在 InitializeComponent 調用后添加任何構造函數代碼
   //
  }
  /// <summary>
  /// 清理所有正在使用的資源。
  /// </summary>
  protected override void Dispose( bool disposing )
  {
   if( disposing )
   {
    if (components != null)
    {
     components.Dispose();
    }
   }
   base.Dispose( disposing );
  }
  #region Windows Form Designer generated code
  /// <summary>
  /// 設計器支持所需的方法 - 不要使用代碼編輯器修改
  /// 此方法的內容。
  /// </summary>
  private void InitializeComponent()
  {
   this.crystalReportViewer1 = new
   CrystalDecisions.Windows.Forms.CrystalReportViewer();
   this.button1 = new System.Windows.Forms.Button();
   this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog();
   this.SuspendLayout();
   //
   // crystalReportViewer1
   //
   this.crystalReportViewer1.ActiveViewIndex = -1;
   this.crystalReportViewer1.Dock= System.Windows.Forms.DockStyle.Fill;
   this.crystalReportViewer1.DockPadding.Bottom = 50;
   this.crystalReportViewer1.DockPadding.Left = 5;
   this.crystalReportViewer1.DockPadding.Right = 5;
   this.crystalReportViewer1.DockPadding.Top = 5;
   this.crystalReportViewer1.Name = "crystalReportViewer1";
   this.crystalReportViewer1.ReportSource = null;
   this.crystalReportViewer1.Size = new System.Drawing.Size(292, 273);
   this.crystalReportViewer1.TabIndex = 0;
   //
   // button1
   //
   this.button1.Anchor = System.Windows.Forms.AnchorStyles.Bottom;
   this.button1.Location = new System.Drawing.Point(104, 240);
   this.button1.Name = "button1";
   this.button1.TabIndex = 1;
   this.button1.Text = "打開報表";
   this.button1.Click += new System.EventHandler(this.button1_Click);
   //
   // openFileDialog1
   //
   this.openFileDialog1.Filter = "Crystal Report (*.rpt)|*.rpt|所有文件(*.*)|*.*";
   this.openFileDialog1.Title = "打開水晶報表";
   //
   // Form1
   //
   this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
   this.ClientSize = new System.Drawing.Size(292, 273);
   this.Controls.AddRange(new System.Windows.Forms.Control[] {
    this.button1,
    this.crystalReportViewer1});
   this.Name = "Form1";
   this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
   this.Text = "水晶報表瀏覽器";
   this.ResumeLayout(false);
  }
  #endregion
  /// <summary>
  /// 應用程序的主入口點。
  /// </summary>
  [STAThread]
  static void Main()
  {
   Application.Run(new Form1());
  }
  private void button1_Click(object sender, System.EventArgs e)
  {
   try
   {
    if(openFileDialog1.ShowDialog()==DialogResult.OK)
     this.crystalReportViewer1.ReportSource = @openFileDialog1.FileName;
     //加載水晶報表,將資源報表綁定到水晶報表查看器
   }
   catch(Exception error)
   {
    MessageBox.Show(error.ToString(),"錯誤"); //處理異常錯誤
   }
  }
 }
}


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 久久午夜国产 | 精品伊人 | 色播久久 | 日本aaaa片毛片免费观蜜桃 | 国产一国产一级毛片视频 | 中文字幕h| 天天草夜夜爽 | h视频免费在线 | 一级黄色毛片免费 | 国产成人精品一区二区三区电影 | 欧美成年人视频在线观看 | 亚洲导航深夜福利涩涩屋 | wwwxxx免费视频 | 制服丝袜成人动漫 | 亚洲91网| 国产精品自拍啪啪 | 国产高清一区 | 亚洲91精品| 国产黄色毛片 | 国产精品视频二区不卡 | 日韩欧美电影一区二区三区 | 国产精品一区二区三区在线 | 亚洲成人福利网站 | 女人叉开腿让男人桶 | 91成人午夜性a一级毛片 | 久久亚洲美女视频 | 91九色网 | 电影av在线 | 特黄一级小说 | 日本欧美一区二区三区在线播 | 男女生羞羞视频网站在线观看 | 精品国产一区二区三区在线 | 天天看成人免费毛片视频 | 亚洲网站在线 | 欧美精品a∨在线观看不卡 午夜精品影院 | 精品人伦一区二区三区蜜桃网站 | 亚洲成人激情在线 | 婷婷中文字幕一区二区三区 | 日本视频免费看 | 激情久久婷婷 | 亚洲网在线观看 |