-- 作者:有点色
-- 发布时间:2017/6/6 15:10:00
--
比较困难,如果要这样,你就必须写一个通用的生成报表的代码
Dim doc As new PrintDoc
Doc.PageSetting.Width=180 Doc.PageSetting.Height=100 Doc.PageSetting.TopMargin=10 Doc.PageSetting.BottomMargin=0 Doc.PageSetting.LeftMargin=10 Doc.PageSetting.RightMargin=10
Dim wbl As Double = Doc.PageSetting.Width.value / e.Form.Width Dim hbl As Double = Doc.PageSetting.Height.value / e.Form.Height For Each c As object In e.Form.controls Dim nc As object If Typeof c Is winform.textbox OrElse Typeof c Is winform.label Then nc = new prt.RenderText nc.Text = c.text Else End If If nc IsNot Nothing Then nc.x = new C1.C1Preview.Unit(CStr(c.left * wbl)) nc.y = new C1.C1Preview.Unit(CStr(c.Top * hbl)) nc.width = new C1.C1Preview.Unit(CStr(c.width * wbl)) nc.height = new C1.C1Preview.Unit(CStr(c.height * hbl)) Doc.Body.Children.Add(nc) End If Next
doc.Preview()
|
-- 作者:有点色
-- 发布时间:2017/6/6 15:17:00
--
完善一点的代码这样写
Dim doc As new PrintDoc
Doc.PageSetting.Width=180 Doc.PageSetting.Height=100 Doc.PageSetting.TopMargin=10 Doc.PageSetting.BottomMargin=0 Doc.PageSetting.LeftMargin=10 Doc.PageSetting.RightMargin=10
Dim wbl As Double = Doc.PageSetting.Width.value / e.Form.Width Dim hbl As Double = Doc.PageSetting.Height.value / e.Form.Height For Each obj As object In e.Form.controls Dim nc As object If Typeof obj Is winform.textbox OrElse Typeof obj Is winform.label Then nc = new prt.RenderText nc.Text = obj.text nc.Style.Font = obj.Font ElseIf Typeof obj Is winform.Table Then Dim rt As New prt.RenderTable \'定义一个新表格 Dim tb As Table = obj.Table Dim ColNames As New List(Of String) For Each cl As Col In tb.Cols \'排除隐藏列 If cl.Visible Then ColNames.Add(cl.Name) End If Next \'rt.Width = "Auto" \'表格宽度为自动,也就是等于各列设置宽度之和 rt.SplitHorzBehavior = prt.SplitBehaviorEnum.SplitIfNeeded \'表格宽度超出页宽时,可以水平换页 rt.Style.Font = tb.Font For c As Integer = 0 To ColNames.Count - 1 \'逐列设置和填入内容 rt.Cells(0,c).Text = ColNames(c) \'列名作为标题 rt.Cells(0,c).Style.TextAlignHorz = prt.AlignHorzEnum.Center \'标题内容水平居中 \' rt.Cols(c).Width = tb.Cols(ColNames(c)).PrintWidth \'列宽等于实际列宽 If tb.Cols(ColNames(c)).IsNumeric OrElse tb.Cols(ColNames(c)).IsDate Then \'如果是数值或日期列 rt.Cols(c).Style.TextAlignHorz = prt.AlignHorzEnum.Right \'数据水平靠右 End If For r As Integer = 0 To tb.Rows.Count -1 \'开始填入该列内容 rt.Cells(r + 1, c).Text = tb.Rows(r)(ColNames(c)) Next Next rt.Style.Gridlines.All = New prt.Linedef(Color.Gray) \'灰色网格线 rt.CellStyle.Spacing.All = 0.5 \'单元格内距设为0.5毫米 rt.Rows(0).Style.TextAlignHorz = prt.AlignHorzEnum.Center \'第一行内容水平居中 \'rt.RowGroups(0,1).Header = prt.TableHeaderEnum.All \'利用行组,将第一行设为表头. nc = rt End If If nc IsNot Nothing Then nc.x = new C1.C1Preview.Unit(CStr(obj.left * wbl)) nc.y = new C1.C1Preview.Unit(CStr(obj.Top * hbl)) nc.width = new C1.C1Preview.Unit(CStr(obj.width * wbl)) nc.height = new C1.C1Preview.Unit(CStr(obj.height * hbl)) Doc.Body.Children.Add(nc) End If Next
doc.Preview()
|
-- 作者:aidimeng
-- 发布时间:2018/12/23 15:08:00
--
.NET Framework 版本:2.0.50727.5485 Foxtable 版本:2018.9.9.1 错误所在事件:窗口,报告,Button1,Click 详细错误信息: 添加的项目已经有所有者了。 去掉
Doc.Body.Children.Add(nc)
不报错,但现实的是空白 panel上有 web 与 lab 两个控件
|