关于C1PrintPreviewDialog的疑问

bonesoup bonesoup 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
我将例子C:\Program Files\ComponentOne Studio.NET 2.0\C1Report\Samples\CS\FlexReport
由C#例转换成VB

但却无法预览,空白.
不知道哪里出了问题.

以下是我转换后的VB代码(分为窗体代码与类代码),请高手一定帮忙指点一下.谢谢!!!

--------------------------------------------------------窗体代码:

Imports C1.Win.C1FlexGrid
Imports System.String
Imports C1.C1Report
Imports C1.Win.C1Preview
Imports System.Data.OleDb


Imports System
Imports System.Drawing
Imports System.Collections
Imports System.ComponentModel
Imports System.Windows.Forms
Imports System.Data

Public Class Form

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim mdbFile As String = "C:\Program Files\ComponentOne Studio.NET 2.0\Common\NWIND.MDB"
Dim conn As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + mdbFile + ";"
Dim rs As String = "select * from customers"
Dim da As OleDbDataAdapter = New OleDbDataAdapter(rs, conn)
Dim dt As DataTable = New DataTable()
da.Fill(dt)
fg.DataSource = dt
fg.Cols(0).Width = fg.Rows(0).HeightDisplay
fg.ShowCursor = True
End Sub
Private Sub rbPrint_Click()



Call BuildReportDefinition()

_c1r.DoEvents = False
_c1r.Render()
Dim pd As C1PrintPreviewDialog = New C1PrintPreviewDialog
pd.Document = _c1r
pd.ShowDialog()
End Sub

Private Sub BuildReportDefinition()

' initialize report
_c1r.Clear()
_c1r.Layout.Orientation = OrientationEnum.Landscape
_c1r.Layout.MarginLeft = 500

' add header section
Dim s As Section = _c1r.Sections(SectionTypeEnum.Header)
s.Visible = True
s.Height = 700
Dim f As Field = s.Fields.Add("fldTitle", "Flex-based report", 0, 0, 4000, 700)
f.Font = New Font("Tahoma", 14, FontStyle.Bold)

' add page header and detail sections
Dim sHdr As Section = _c1r.Sections(SectionTypeEnum.PageHeader)
sHdr.Visible = True
sHdr.Height = 400

Dim sDtl As Section = _c1r.Sections(SectionTypeEnum.Detail)
sDtl.Visible = True
sDtl.Height = 100
sDtl.CanGrow = True

' populate header and detail sections
Dim fntHdr As Font = New Font("Tahoma", 8, FontStyle.Bold)
Dim fntDtl As Font = New Font("Tahoma", 8, FontStyle.Regular)
Dim rc As Rectangle = New Rectangle(0, 0, sDtl.Height, 0)

For Each col As Column In fg.Cols

' calculate field rectangle in twips
rc.Width = col.WidthDisplay * 1440 / 96 + 200

' create field in page header section
rc.Height = sHdr.Height
f = sHdr.Fields.Add("fh" + col.Name, col.Name, rc)
f.Font = fntHdr
f.ForeColor = Color.Navy
f.Align = FieldAlignEnum.LeftBottom

' create field in detail section
rc.Height = sDtl.Height
f = sDtl.Fields.Add("fd" + col.Name, col.Name, rc)
f.Font = fntDtl
f.Calculated = True
f.CanGrow = True
f.Format = col.Format

' move on to next field
rc.Offset(rc.Width, 0)
If (rc.Left > 10 * 1440) Then Exit For
Next
' assign data source
Dim ds As FlexDataSource = New FlexDataSource(fg)
_c1r.DataSource.Recordset = ds
End Sub


Private Sub fg_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles fg.Click

End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
rbPrint_Click()
End Sub
End Class


------------------------------------------------------类代码
Imports System.IO
Imports C1.C1Report
Imports C1.Win.C1FlexGrid

Imports System
Imports System.Drawing
Imports System.Collections
Imports System.ComponentModel
Imports System.Windows.Forms
Imports System.Data

Public Class FlexDataSource
Implements IC1ReportRecordset

' shared mamebers: field names and types
Private _flex As C1FlexGrid
Private _row As Integer

' ** Constructor

Public Sub New(ByVal flex As C1FlexGrid)
_flex = flex
_row = 0


End Sub



' ** IC1ReportRecordset members

' get recordset information

Public Function GetFieldNames() As String() Implements IC1ReportRecordset.GetFieldNames

Dim count As Integer = _flex.Cols.Count - _flex.Cols.Fixed
Dim fieldNames(count) As String
For i As Integer = 0 To count - 1

fieldNames(i) = _flex.Cols(i + _flex.Cols.Fixed).Name
i += 1
Next

Return fieldNames
End Function

Public Function GetFieldTypes() As Type() Implements IC1ReportRecordset.GetFieldTypes
Dim count As Integer = _flex.Cols.Count - _flex.Cols.Fixed
Dim fieldTypes(count) As Type
For i As Integer = 0 To count - 1

fieldTypes(i) = _flex.Cols(i + _flex.Cols.Fixed).DataType
i += 1
Next

Return fieldTypes
End Function

Public Function GetFieldValue(ByVal fieldIndex As Integer) As Object Implements IC1ReportRecordset.GetFieldValue

Return _flex(_row + _flex.Rows.Fixed, fieldIndex + _flex.Cols.Fixed)
End Function

' sort/filter
Public Sub ApplyFilter(ByVal filter As String) Implements IC1ReportRecordset.ApplyFilter
' not implemented
End Sub
Public Sub ApplySort(ByVal sort As String) Implements IC1ReportRecordset.ApplySort
' not implemented
End Sub

' cursor positioning
Public Function BOF() As Boolean Implements IC1ReportRecordset.BOF
BOF = (_row = 0)
End Function
Public Function EOF() As Boolean Implements IC1ReportRecordset.EOF
EOF = (_row >= _flex.Rows.Count - _flex.Rows.Fixed)
End Function
Public Function GetBookmark() As Integer Implements IC1ReportRecordset.GetBookmark
GetBookmark = _row
End Function
Public Sub SetBookmark(ByVal bkmk As Integer) Implements IC1ReportRecordset.SetBookmark
_row = bkmk
End Sub
Public Sub MoveFirst() Implements IC1ReportRecordset.MoveFirst
_row = 0
End Sub
Public Sub MoveLast() Implements IC1ReportRecordset.MoveLast
_row = _flex.Rows.Count - _flex.Rows.Fixed - 1
End Sub
Public Sub MovePrevious() Implements IC1ReportRecordset.MovePrevious
'If _row > 0 Then
_row = _row - 1
'End If
End Sub
Public Sub MoveNext() Implements IC1ReportRecordset.MoveNext
'If _row < _flex.Rows.Count - _flex.Rows.Fixed Then
_row = _row + 1
'End If
End Sub

End Class

...全文

相关推荐

评论 3
收藏 已收藏
分享
返回顶部
bonesoup
VB 16,718 成员 110,520 内容