📄 crystalreporttest1.cs
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
namespace test1
{
/// <summary>
/// Summary description for CrystalReportTest1.
/// </summary>
public class CrystalReportTest1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Button button1;
private System.Windows.Forms.OpenFileDialog openFileDialog1;
private CrystalDecisions.Windows.Forms.CrystalReportViewer crystalReportViewer1;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
public CrystalReportTest1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
//设置各个控件的属性
//setFrom();
}
/// <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.button1 = new System.Windows.Forms.Button();
this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog();
this.crystalReportViewer1 = new CrystalDecisions.Windows.Forms.CrystalReportViewer();
this.SuspendLayout();
//
// button1
//
this.button1.Anchor = System.Windows.Forms.AnchorStyles.Bottom;
this.button1.Location = new System.Drawing.Point(238, 244);
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 = "打开水晶报表";
//
// 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.Location = new System.Drawing.Point(0, 0);
this.crystalReportViewer1.Name = "crystalReportViewer1";
this.crystalReportViewer1.ReportSource = null;
this.crystalReportViewer1.Size = new System.Drawing.Size(560, 277);
this.crystalReportViewer1.TabIndex = 0;
//
// CrystalReportTest1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(560, 277);
this.Controls.Add(this.button1);
this.Controls.Add(this.crystalReportViewer1);
this.Name = "CrystalReportTest1";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "CrystalReportTest1水晶报表浏览器";
this.ResumeLayout(false);
}
#endregion
#region 设置各个控件的属性
protected void setFrom()
{
this.crystalReportViewer1.Dock = System.Windows.Forms.DockStyle.Fill;
//停靠方式为充满整个窗体
//展开+DockPadding
this.crystalReportViewer1.DockPadding.Bottom = 100;
//底部空出放置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 = "打开水晶报表";
//打开文件对话框的标题
}
#endregion
#region 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(),"错误");
}
}
#endregion
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -