求助:如何打印MSFlexGrid中的数据?

chuchu 2001-06-27 10:54:39
MSFlexGrid中数据由手工添加(不是从数据库取的),如何用报表设计器将数据打印出来。
...全文
159 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
woosilence 2001-11-20
  • 打赏
  • 举报
回复
upup
Richard2001 2001-11-20
  • 打赏
  • 举报
回复
可以做个简单的预览和打印功能:
你在Form中间加一个PictureBox,设Appearance=0,大小比例与一张打印纸相似。
再加两个按钮:“预览“(Preview)和“打印“(Print)按钮。

Sub SetData(obj As Object)
If TypeOf obj Is Picture Then
obj.Cls
End If

On Error GoTo exit_data

Dim CX, CY, i, curY, curX
Dim StepRow, lColor, adjRowHeight, iBottomRight

lColor = obj.ForeColor
'首行显示公司名称
CX = 4
obj.Font.Bold = False
obj.Font.Size = 9
obj.CurrentY = CX
obj.CurrentX = obj.Width / 2 - obj.TextWidth("地球")
'obj.ForeColor = RGB(256, 0, 0)
obj.Print "地球公司"
StepRow = obj.TextHeight("A")
'标题
CX = CX + StepRow
obj.Font.Bold = True
obj.Font.Size = 2 * 9
obj.CurrentY = CX
obj.CurrentX = obj.Width / 2 - obj.TextWidth("存款")
obj.ForeColor = RGB(256, 0, 0) '红色
obj.Print "存款单据"
StepRow = obj.TextHeight("A")
'首部信息第一行
obj.ForeColor = lColor '恢复
CX = CX + StepRow
obj.Font.Bold = False
obj.Font.Size = 9
obj.CurrentY = CX: obj.CurrentX = 150
obj.Print "左"
obj.CurrentY = CX: obj.CurrentX = obj.Width / 2 - obj.TextWidth("中") / 2
obj.Print "中"
obj.CurrentY = CX: obj.CurrentX = obj.ScaleWidth - 150 - obj.TextWidth("右")
obj.Print "右"


'=================画行线=================
curY = CX + StepRow: curX = 150

For i = 1 To 5
If i = 1 Then
obj.DrawWidth = 2
Else
obj.DrawWidth = 1
End If
obj.Line (curX, curY)-(obj.ScaleWidth - 150, curY)
iBottomRight = curY
'~~~~~
adjRowHeight = obj.TextHeight("A") + 3
curY = curY + adjRowHeight + 4
Next

'=============画竖线=================
curY = CX + StepRow: curX = 150
For i = 1 To 2
obj.DrawWidth = 1
obj.Line (curX, curY)-(curX, iBottomRight)
curX = curX + obj.Width / 2 - obj.TextWidth("中") / 2
Next
obj.Line (obj.ScaleWidth - 150, curY)-(obj.ScaleWidth - 150, iBottomRight)

'==============打印数据:可从MSFlexGrid中来==================
Dim str
str = "打印数据"
curY = CX + StepRow + ((adjRowHeight + 4) / 2) - obj.TextHeight("A") / 2
curX = (150 + obj.Width / 2) / 2 - obj.TextWidth(str) / 2
obj.CurrentY = curY
obj.CurrentX = curX
obj.Print str

'...

Exit Sub

exit_data:
MsgBox Error
Exit Sub
End Sub

Private Sub Preview_Click()
SetData Pic
End Sub

Private Sub Print_Click()
SetData Printer
Printer.EndDoc
End Sub

chuchu 2001-06-28
  • 打赏
  • 举报
回复
呵呵,找到一个深圳精诺威打印控件,感觉很不错,比报表设计器好多了。需要的话发封Mail给我。
miss_you@263.net
everyask 2001-06-27
  • 打赏
  • 举报
回复
printer.paintpicture msflexgrid1.picture,1000,1000
everyask 2001-06-27
  • 打赏
  • 举报
回复
报表题目可以用printer对象打印出来啊。
如果你不想直接打印,可以使用picturebox做预览。
语句是一样的,只是printer改为picture1就行了。
sindia 2001-06-27
  • 打赏
  • 举报
回复
不要用报表设计器了,这种东西太烂。不如自己写程序,稍微控制一下就可以了,很简单的。
chuchu 2001-06-27
  • 打赏
  • 举报
回复
如果用printer的话,报表题目就打不出来了。
算了,干脆先写到数据库的表中,再从表中取数据。
mazhayang 2001-06-27
  • 打赏
  • 举报
回复
我有这个控件,你要吗,不过不能预览
MEMPHISTO 2001-06-27
  • 打赏
  • 举报
回复
可以试着将数据导出到Excel打印。
everyask 2001-06-27
  • 打赏
  • 举报
回复
调整底色为单色,然后调整左边线与上边线。
换用mshflexgrid效果会好一些的。
如果要分页,可以用一个不可见的grid做辅助,然后编程控制(要与printer对象结合使用)。

haitaoyu 2001-06-27
  • 打赏
  • 举报
回复
gz
chuchu 2001-06-27
  • 打赏
  • 举报
回复
不行呀,格式不好控制,打出来又不美观。

7,763

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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