# Re: 如何将MSFlexGrid显示的资料全都印出来呢？

Posted by 战豪 on July 09, 1999 at 01:32:33:

In Reply to: 如何将MSFlexGrid显示的资料全都印出来呢？ posted by 大头 on July 07, 1999 at 19:15:36:

: 我用Data控制项及Adodc来存取Access的东西，
: 而我以MSFlexGrid来显示资料，
: 请问各位高手...我要如何将MSFlexGrid显示的资料全都印出来呢？
: 我不是要印表单哦...我是要印表单内容哦....
: thanks......

假设你之资料为平均长度,可试试此CommandButton程序:

Private Sub cmdPrint_Click()
Dim aNo As Integer '存放msFlexGrid列数变数
Dim bNo as Integer '存放msFlexGrid栏数变数
Dim xHG As Integer '存放Printer垂直位置变数
Dim i As Integer, j as Integer '计算器
Dim tStr as String '存放每列内容的变数
Printer.EndDoc '呼叫印表机停止之前工序
Printer.FontSize = 12 '设定列印文字大小
xHG = 567 * 1.5
Printer.CurrentX = 567
Printer.CurrentY = xHG
With myGrid
.Visible = False '避免读取Cell资料时闪烁
aNo = .Rows - 1
bNo = .Cols - 1
For i = 0 To aNo
.Row = i
For j = 0 to bNo
.Col = j
if j = 0 then
tStr = .Text
else
tStr = tStr & vbTab & .Text
end if
Next j
Printer.Print tStr
xHG = xHG + 567
Printer.CurrentX = 567
Printer.CurrentY = xHG
Next i
.Visible = True
End With
Printer.EndDoc
End Sub

Printer的CurrentX和CurrentY,就是列印时的座标,而tStr变数中之vbTab只是籍化的移位函数! ^_^

Follow Ups: