关于C1PrintPreviewDialog的疑问

bonesoup 2009-03-06 05:02:20
我将例子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

...全文
172 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
bonesoup 2009-03-09
  • 打赏
  • 举报
回复
没有人用VB.net +C1PrintPreviewDialog ?
都用C#?
bonesoup 2009-03-09
  • 打赏
  • 举报
回复
我逐步执行到 pd.Document = _c1r ,发现c1r的filed属性计数13,page属性计数3
这应该表示c1r是有内容的,为何却显示不出来呢/
郁闷.
bonesoup 2009-03-07
  • 打赏
  • 举报
回复
没有人知道么?

16,555

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧