水晶报表用户自定义打印(c/s)

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Winform自定义打印模板是一种在Windows Forms应用程序中自定义打印输出的方法。通过使用自定义打印模板,用户可以更改打印布局、格式和样式,以满足特定的打印需求和设计要求。 要创建Winform自定义打印模板,首先需要创建一个打印文档对象,并且定义打印输出的布局和格式。可以使用.NET Framework提供的PrintDocument类来实现这一步骤。接着,可以在此文档对象中添加打印事件处理程序,以便在打印时对文档内容进行自定义操作,比如绘制文本、图像和表格等。 另外,还可以使用自定义打印预览控件来展示模板打印的效果,并且让用户能够在打印之前查看和调整打印输出的内容。通过自定义打印预览控件,可以为用户提供更加直观和友好的打印操作界面,以便他们更好地理解和控制打印的结果。 除此之外,Winform自定义打印模板还可以与数据绑定技术相结合,实现将数据与打印模板绑定,以便快速生成基于数据的打印内容。例如,可以使用数据绑定技术将数据库中的数据直接输出到自定义打印模板中,从而实现自动生成报表、发票和标签等功能。 总之,Winform自定义打印模板提供了一种相对灵活、定制化程度较高的打印输出方式,能够满足不同用户打印需求的个性化要求,为Windows Forms应用程序的打印功能增添了更多的定制化和扩展性。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值