Public Class Form1
Inherits System.Windows.Forms.Form
#Region " Windows 窗体设计器生成的代码 "
Public Sub New()
MyBase.New()
'该调用是 Windows 窗体设计器所必需的。
InitializeComponent()
'在 InitializeComponent() 调用之后添加任何初始化
End Sub
'窗体重写处置以清理组件列表。
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Windows 窗体设计器所必需的
Private components As System.ComponentModel.IContainer
'注意:以下过程是 Windows 窗体设计器所必需的
'可以使用 Windows 窗体设计器修改此过程。
'不要使用代码编辑器修改它。
Friend WithEvents PictureBox1 As System.Windows.Forms.PictureBox
Friend WithEvents SSTab1 As System.Windows.Forms.TabControl
Friend WithEvents TabPage2 As System.Windows.Forms.TabPage
Friend WithEvents TabPage1 As System.Windows.Forms.TabPage
Friend WithEvents AxCRDesignerCtrl101 As AxCRDESIGNERCTRLLib10.AxCRDesignerCtrl10
Friend WithEvents AxCrystalActiveXReportViewer1 As AxCrystalActiveXReportViewerLib10.AxCrystalActiveXReportViewer
Friend WithEvents ToolBar1 As System.Windows.Forms.ToolBar
Friend WithEvents tbbNew As System.Windows.Forms.ToolBarButton
Friend WithEvents tbbOpen As System.Windows.Forms.ToolBarButton
Friend WithEvents tbbSave As System.Windows.Forms.ToolBarButton
Friend WithEvents tbbClose As System.Windows.Forms.ToolBarButton
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(Form1))
Me.PictureBox1 = New System.Windows.Forms.PictureBox
Me.SSTab1 = New System.Windows.Forms.TabControl
Me.TabPage1 = New System.Windows.Forms.TabPage
Me.AxCRDesignerCtrl101 = New AxCRDESIGNERCTRLLib10.AxCRDesignerCtrl10
Me.TabPage2 = New System.Windows.Forms.TabPage
Me.AxCrystalActiveXReportViewer1 = New AxCrystalActiveXReportViewerLib10.AxCrystalActiveXReportViewer
Me.ToolBar1 = New System.Windows.Forms.ToolBar
Me.tbbNew = New System.Windows.Forms.ToolBarButton
Me.tbbOpen = New System.Windows.Forms.ToolBarButton
Me.tbbSave = New System.Windows.Forms.ToolBarButton
Me.tbbClose = New System.Windows.Forms.ToolBarButton
Me.SSTab1.SuspendLayout()
Me.TabPage1.SuspendLayout()
CType(Me.AxCRDesignerCtrl101, System.ComponentModel.ISupportInitialize).BeginInit()
Me.TabPage2.SuspendLayout()
CType(Me.AxCrystalActiveXReportViewer1, System.ComponentModel.ISupportInitialize).BeginInit()
Me.SuspendLayout()
'
'PictureBox1
'
Me.PictureBox1.BackColor = System.Drawing.SystemColors.ActiveCaptionText
Me.PictureBox1.Location = New System.Drawing.Point(624, 8)
Me.PictureBox1.Name = "PictureBox1"
Me.PictureBox1.Size = New System.Drawing.Size(96, 32)
Me.PictureBox1.TabIndex = 3
Me.PictureBox1.TabStop = False
'
'SSTab1
'
Me.SSTab1.Controls.Add(Me.TabPage1)
Me.SSTab1.Controls.Add(Me.TabPage2)
Me.SSTab1.ItemSize = New System.Drawing.Size(0, 17)
Me.SSTab1.Location = New System.Drawing.Point(0, 40)
Me.SSTab1.Name = "SSTab1"
Me.SSTab1.SelectedIndex = 0
Me.SSTab1.Size = New System.Drawing.Size(728, 528)
Me.SSTab1.TabIndex = 2
'
'TabPage1
'
Me.TabPage1.Controls.Add(Me.AxCRDesignerCtrl101)
Me.TabPage1.Location = New System.Drawing.Point(4, 21)
Me.TabPage1.Name = "TabPage1"
Me.TabPage1.Size = New System.Drawing.Size(720, 503)
Me.TabPage1.TabIndex = 0
Me.TabPage1.Text = "设计"
'
'AxCRDesignerCtrl101
'
Me.AxCRDesignerCtrl101.ContainingControl = Me
Me.AxCRDesignerCtrl101.Enabled = True
Me.AxCRDesignerCtrl101.Location = New System.Drawing.Point(0, 0)
Me.AxCRDesignerCtrl101.Name = "AxCRDesignerCtrl101"
Me.AxCRDesignerCtrl101.OcxState = CType(resources.GetObject("AxCRDesignerCtrl101.OcxState"), System.Windows.Forms.AxHost.State)
Me.AxCRDesignerCtrl101.Size = New System.Drawing.Size(720, 504)
Me.AxCRDesignerCtrl101.TabIndex = 0
'
'TabPage2
'
Me.TabPage2.Controls.Add(Me.AxCrystalActiveXReportViewer1)
Me.TabPage2.Location = New System.Drawing.Point(4, 21)
Me.TabPage2.Name = "TabPage2"
Me.TabPage2.Size = New System.Drawing.Size(720, 503)
Me.TabPage2.TabIndex = 1
Me.TabPage2.Text = "预览"
'
'AxCrystalActiveXReportViewer1
'
Me.AxCrystalActiveXReportViewer1.ContainingControl = Me
Me.AxCrystalActiveXReportViewer1.Enabled = True
Me.AxCrystalActiveXReportViewer1.Location = New System.Drawing.Point(0, 0)
Me.AxCrystalActiveXReportViewer1.Name = "AxCrystalActiveXReportViewer1"
Me.AxCrystalActiveXReportViewer1.OcxState = CType(resources.GetObject("AxCrystalActiveXReportViewer1.OcxState"), System.Windows.Forms.AxHost.State)
Me.AxCrystalActiveXReportViewer1.Size = New System.Drawing.Size(720, 496)
Me.AxCrystalActiveXReportViewer1.TabIndex = 0
'
'ToolBar1
'
Me.ToolBar1.Buttons.AddRange(New System.Windows.Forms.ToolBarButton() {Me.tbbNew, Me.tbbOpen, Me.tbbSave, Me.tbbClose})
Me.ToolBar1.DropDownArrows = True
Me.ToolBar1.Location = New System.Drawing.Point(0, 0)
Me.ToolBar1.Name = "ToolBar1"
Me.ToolBar1.ShowToolTips = True
Me.ToolBar1.Size = New System.Drawing.Size(728, 41)
Me.ToolBar1.TabIndex = 6
'
'tbbNew
'
Me.tbbNew.Text = " New "
'
'tbbOpen
'
Me.tbbOpen.Text = "Open"
'
'tbbSave
'
Me.tbbSave.Text = "Save"
'
'tbbClose
'
Me.tbbClose.Text = "Close"
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
Me.ClientSize = New System.Drawing.Size(728, 573)
Me.Controls.Add(Me.ToolBar1)
Me.Controls.Add(Me.SSTab1)
Me.Name = "Form1"
Me.Text = "昆供报表定制"
Me.SSTab1.ResumeLayout(False)
Me.TabPage1.ResumeLayout(False)
CType(Me.AxCRDesignerCtrl101, System.ComponentModel.ISupportInitialize).EndInit()
Me.TabPage2.ResumeLayout(False)
CType(Me.AxCrystalActiveXReportViewer1, System.ComponentModel.ISupportInitialize).EndInit()
Me.ResumeLayout(False)
End Sub
#End Region
Dim m_Application As New CRAXDDRT.Application
Dim m_Report As CRAXDDRT.Report
'++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
'该版本用到的是水晶报表10高级开发版,不能用企业版,因为企业版缺少控件支持
'程序需要用到CRDesignerCtrl.DLL,然后还要COM引用 crystal reports activex designer design and ruantime library 10.0
'程序还需要添加两个com组件,embeddable crystal reports designer control 10.0 和 crystal activex report viewer control 10.0
'就可以运新了
'++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
SSTab1.TabIndex = 0
AxCrystalActiveXReportViewer1.EnableExportButton = True
AxCRDesignerCtrl101.DisplayToolbar = True
End Sub
Public Sub DisplayReport()
AxCRDesignerCtrl101.ReportObject = m_Report '指定设计控件的报表源
AxCRDesignerCtrl101.EnableHelp = False
AxCrystalActiveXReportViewer1.ReportSource = m_Report '指定预览控件报表源
AxCrystalActiveXReportViewer1.Zoom(1)
AxCrystalActiveXReportViewer1.ViewReport()
End Sub
Private Sub ToolBar1_ButtonClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ToolBarButtonClickEventArgs) Handles ToolBar1.ButtonClick
Try
Select Case Trim(e.Button.Text)
Case "New"
m_Report = Nothing
m_Report = m_Application.OpenReport(Application.StartupPath & "/Report1.rpt", 1) '打开空白rpt
DisplayReport()
Case "Open"
Dim dlg As New OpenFileDialog
dlg.Title = "请选择rpt格式文件"
dlg.Filter = "Crystal Reports (*.rpt)|*.rpt|All Files (*.*)|*.*"
dlg.InitialDirectory = "C:/Program Files/Microsoft Visual Studio.NET/Crystal Reports/Samples/Reports"
If (dlg.ShowDialog() = DialogResult().OK) Then
m_Report = Nothing
Me.Cursor = Cursors.WaitCursor '定义鼠标样式
m_Report = m_Application.OpenReport(dlg.FileName, 1) '打开已存在的rpt
Me.Cursor = Cursors.Default
DisplayReport()
End If
dlg.Dispose() '释放dialog资源,不然会出错
Case "Save"
Dim dlgSave As New SaveFileDialog
dlgSave.Title = "请保存rpt格式文件"
dlgSave.Filter = "Crystal Reports (*.rpt)|*.rpt"
dlgSave.InitialDirectory = "c:/"
If (dlgSave.ShowDialog() = DialogResult.OK) Then
m_Report.SaveAs(dlgSave.FileName, CRAXDDRT.CRReportFileFormat.crDefaultFileFormat) '保存修改后的rpt
End If
dlgSave.Dispose() '释放dialog资源,不然会出错
Case "Close"
m_Report = Nothing
Me.Close()
End Select
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
Private Sub Form1_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
Me.AxCRDesignerCtrl101.Dispose() '释放控件资源
Me.AxCrystalActiveXReportViewer1.Dispose()
End Sub
End Class