vb里面的水晶報表打印控件:CrystalReportViewer
用到的dll文件:
水晶報表打印其實很簡單,只要創建報表對象,再對其傳遞數據就可以打印出來。當然所傳遞的數據要與水晶報表設計里面的數據一致:
Public Overloads Sub ShowDialog(ByVal netDs As DataSet, ByVal strPath As String, Optional ByVal showPrint As Boolean = True, Optional ByVal showExport As Boolean = True) Try If netDs.Tables(0).Rows.Count > 0 Then Dim rpt As New ReportDocument rpt.Load(strPath) rpt.SetDataSource(netDs) CRV.ReportSource = rpt CRV.ShowPrintButton = showPrint CRV.ShowExportButton = showExport Dim t As New ComboBox t.Visible = True ShowDialog() Else MsgBox("Not print Data!", MsgBoxStyle.Critical) End If Catch ex As Exception MsgBox(ex.ToString) End Try End Sub
調用例子:在其他設計界面,當要打印之時,直接傳遞參數到打印界面即可。
Dim daOM As SqlDataAdapter Dim cmbOM As SqlCommandBuilder Dim dsOM As New DataSet Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Try daOM = New SqlDataAdapter("select top 5 * from facd321 ", GetConn) cmbOM = New SqlCommandBuilder(daOM) daOM.Fill(dsOM, "OM") With dg .DataSource = dsOM.Tables("OM") .WindowLaguage = myDataGrid.myDatagrid.LanguageType.English .FilterBar = True Dim ii As Int16 For ii = 0 To .Splits(0).DisplayColumns.Count - 1 .Splits(0).DisplayColumns(ii).Locked = True Next End With Catch ex As Exception MsgBox(ex.Message, MsgBoxStyle.Exclamation, "Error") End Try End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Try Me.Cursor = Cursors.WaitCursor Dim f As New Form1 AddBarcodeImages(dsOM.Tables(0)) f.ShowDialog(dsOM, Application.StartupPath & "\Reports\bundle.rpt") Catch ex As Exception MsgBox(ex.ToString) Finally Me.Cursor = Cursors.Default End Try End Sub
報表設計:
運行效果: