📄 frmgridprint.frm
字号:
ElseIf pageNum = pageCount Then
If intPartIndex = intPartCount Then cmdNext.Enabled = False '当前页号减1
End If
PrintPreview percent
End Sub
'****************************************************
' 后翻一页
'****************************************************
Private Sub cmdNext_Click()
Dim strPercent As String
Dim percent As Long
cmdPrevious.Enabled = True
strPercent = cboScale.List(cboScale.ListIndex)
strPercent = Left(strPercent, Len(strPercent) - 1)
percent = CLng(strPercent)
If intPartIndex < intPartCount Then
intPartIndex = intPartIndex + 1
Else
intPartIndex = 1
End If
If pageNum = pageCount Then
If intPartIndex = intPartCount Then cmdNext.Enabled = False
Else
If intPartIndex = 1 Then pageNum = pageNum + 1 '当前页数加1
End If
PrintPreview percent
End Sub
'****************************************************
' 页面设置
'****************************************************
Private Sub cmdOption_Click()
Dim strPercent As String
Dim percent As Long
intRange = 1
intStart = 1
intEnd = pageCount
' 显示打印设置窗口
frmOption.Show vbModal
' 设置打印页码范围
Select Case intRange
Case 1
intStart = 1
intEnd = pageCount
Case 3
If intStart = 0 Then intStart = 1
End Select
PageAnalyze
If pageNum > pageCount Then pageNum = 1
' 根据重新设置的打印参数预览当前页
oldIndex = cboScale.ListIndex
strPercent = cboScale.List(cboScale.ListIndex)
strPercent = Left(strPercent, Len(strPercent) - 1)
percent = CLng(strPercent)
PrintPreview percent
End Sub
'****************************************************
' 前翻一页
'****************************************************
Private Sub cmdPrevious_Click()
Dim strPercent As String
Dim percent As Long
cmdNext.Enabled = True
strPercent = cboScale.List(cboScale.ListIndex)
strPercent = Left(strPercent, Len(strPercent) - 1)
percent = CLng(strPercent)
If intPartIndex > 1 Then
intPartIndex = intPartIndex - 1
Else
intPartIndex = intPartCount
End If
If pageNum = 1 Then
If intPartIndex = 1 Then cmdPrevious.Enabled = False
Else
If intPartIndex = intPartCount Then pageNum = pageNum - 1 '当前页号减1
End If
PrintPreview percent
End Sub
Private Sub cmdPrint_Click()
Dim strPercent As String
Dim percent As Long
Me.MousePointer = 11
' 根据打印范围的选择来设置当前页码或打印页码范围
Select Case intRange
Case 1, 3
pageNum = intStart
Case 2
intStart = pageNum
intEnd = pageNum
End Select
intPartIndex = 1
' 将记录指针移至被选择范围的第一条记录
' 循环调用PrintReport打印报表
Do While pageNum <= intEnd 'rstReport.EOF
rstReport.MoveFirst
rstReport.Move (pageNum - 1) * rowNum
PrintReport 100
If intPartIndex < intPartCount Then
intPartIndex = intPartIndex + 1
Else
pageNum = pageNum + 1
intPartIndex = 1
End If
Loop
' 设置当前页为打印的最后页,重新预览当前页
pageNum = intEnd
cmdNext.Enabled = True
strPercent = cboScale.List(cboScale.ListIndex)
strPercent = Left(strPercent, Len(strPercent) - 1)
percent = CLng(strPercent)
PrintPreview percent
Me.MousePointer = 0
End Sub
Private Sub Form_Load()
Dim i As Integer
Dim j As Integer
Dim k As Integer
Dim l As Integer
Dim intCurX As Integer
' 设置打印机的度量单位为毫米
Printer.ScaleMode = 6
' 初始化数据
oldV = 0
oldH = 0
leftX = 15
topY = 20
rightX = 15
bottomY = 20
' 将每一列记录的基本信息存入数组colInfo中
With objGrid
iFCount = .Count '得到记录集的总列数
ReDim colInfo(iFCount - 1) '根据总列数重新设置数组的长度
intCurX = 0
For i = 0 To iFCount - 1
colInfo(i).Font.Name = "宋体"
colInfo(i).Font.Size = 10
colInfo(i).CurX = intCurX
colInfo(i).CurY = 0
colInfo(i).Width = .Item(i).Width / 56.7
colInfo(i).Height = intHeaderHeight
colInfo(i).Align = 1
colInfo(i).FieldType = 0
colInfo(i).percent = 100
colInfo(i).Text = Trim(.Item(i).Caption)
colInfo(i).style = "ES"
intCurX = intCurX + colInfo(i).Width
Next i
End With
intReportWidth = intCurX '得到报表的总宽度
' 得到每列数据的数据类型,并设置对应的对齐方式
For i = 0 To iFCount - 1
colInfo(i).FieldType = rstReport.Fields(i).Type
Select Case colInfo(i).FieldType
Case 7, 133, 134, 135
colInfo(i).Align = 2
Case 2, 3, 4, 5, 6, 14, 16, 17, 18, 19, 20, 21, 131
colInfo(i).Align = 3
Case Else
colInfo(i).Align = 1
End Select
Next i
' 双层列头结构
If intFlag = 0 Then
With frmGrid
iICount = 0
If .optCol(1).Value Then
iICount = .tvReport.Nodes(1).children
ReDim itemInfo(iICount - 1)
intCurX = 0
k = 0
i = .tvReport.Nodes(1).Child.FirstSibling.Index
itemInfo(k).Text = .tvReport.Nodes(i).Text
itemInfo(k).Font.Name = "宋体"
itemInfo(k).Font.Size = 10
itemInfo(k).Align = 1
itemInfo(k).FieldType = 0
itemInfo(k).percent = 100
itemInfo(k).style = "ES"
If .tvReport.Nodes(i).children > 0 Then
j = .tvReport.Nodes(i).Child.FirstSibling.Index
l = CStr(Mid$(.tvReport.Nodes(j).Key, 4))
itemInfo(k).CurX = colInfo(l).CurX
intCurX = colInfo(l).Width
colInfo(l).CurY = intHeaderHeight / 2
colInfo(l).Height = intHeaderHeight / 2
Do While j <> .tvReport.Nodes(j).LastSibling.Index
l = CStr(Mid$(.tvReport.Nodes(j).Next.Key, 4))
intCurX = intCurX + colInfo(l).Width
colInfo(l).CurY = intHeaderHeight / 2
colInfo(l).Height = intHeaderHeight / 2
j = .tvReport.Nodes(j).Next.Index
Loop
itemInfo(k).CurY = 0
itemInfo(k).Width = intCurX
itemInfo(k).Height = intHeaderHeight / 2
Else
l = CStr(Mid$(.tvReport.Nodes(i).Key, 4))
itemInfo(k).CurX = colInfo(l).CurX
itemInfo(k).CurY = 0
itemInfo(k).Width = colInfo(l).Width
itemInfo(k).Height = 0
End If
Do While i <> .tvReport.Nodes(1).Child.LastSibling.Index
k = k + 1
itemInfo(k).Text = .tvReport.Nodes(i).Next.Text
itemInfo(k).Font.Name = "宋体"
itemInfo(k).Font.Size = 10
itemInfo(k).Align = 1
itemInfo(k).FieldType = 0
itemInfo(k).percent = 100
itemInfo(k).style = "ES"
If .tvReport.Nodes(i).Next.children > 0 Then
j = .tvReport.Nodes(i).Next.Child.FirstSibling.Index
l = CStr(Mid$(.tvReport.Nodes(j).Key, 4))
itemInfo(k).CurX = colInfo(l).CurX
intCurX = colInfo(l).Width
colInfo(l).CurY = intHeaderHeight / 2
colInfo(l).Height = intHeaderHeight / 2
Do While j <> .tvReport.Nodes(j).LastSibling.Index
l = CStr(Mid$(.tvReport.Nodes(j).Next.Key, 4))
intCurX = intCurX + colInfo(l).Width
colInfo(l).CurY = intHeaderHeight / 2
colInfo(l).Height = intHeaderHeight / 2
j = .tvReport.Nodes(j).Next.Index
Loop
itemInfo(k).CurY = 0
itemInfo(k).Width = intCurX
itemInfo(k).Height = intHeaderHeight / 2
Else
l = CStr(Mid$(.tvReport.Nodes(i).Key, 4))
itemInfo(k).CurX = colInfo(l).CurX
itemInfo(k).CurY = 0
itemInfo(k).Width = colInfo(l).Width
itemInfo(k).Height = 0
End If
i = .tvReport.Nodes(i).Next.Index
Loop
End If
End With
End If
' 页面设置
pageNum = 1
PageAnalyze
' 初始化打印范围方式和打印的起始和结束页码
intRange = 1
intStart = 1
intEnd = pageCount
' 初始cboScale控件
oldIndex = 0
cboScale.AddItem "200%"
cboScale.ItemData(cboScale.NewIndex) = 200
cboScale.AddItem "100%"
cboScale.ItemData(cboScale.NewIndex) = 100
cboScale.AddItem "75%"
cboScale.ItemData(cboScale.NewIndex) = 75
cboScale.AddItem "50%"
cboScale.ItemData(cboScale.NewIndex) = 50
cboScale.AddItem "25%"
cboScale.ItemData(cboScale.NewIndex) = 25
cboScale.ListIndex = 1
oldIndex = 1
'****************************************
cmdAbout.Visible = modPub.bShowAbout
'****************************************
End Sub
Private Sub Form_Resize()
' 当窗口变化时,重新设置滚动条位置,frame控件位置
hsl.Width = Me.ScaleWidth - vsl.Width
hsl.Top = Me.ScaleHeight - hsl.Height
vsl.Height = Me.ScaleHeight - Toolbar1.Height - hsl.Height
vsl.Left = Me.ScaleWidth - vsl.Width
fraPic.Height = Me.ScaleHeight - Toolbar1.Height - hsl.Height
fraPic.Width = Me.ScaleWidth - vsl.Width
' 200表示picPreview在fraPic中显示时的上下边距,80表示左右边距
picH = fraPic.Height - 200
picW = fraPic.Width - 80
ResizePic
End Sub
Private Sub hsl_Change()
picPreview.Left = picPreview.Left - (hsl.Value - oldH) * IIf((picPreview.Width - picW) > 32767, 10, 1)
oldH = hsl.Value
End Sub
Private Sub txtPageNum_GotFocus()
txtPageNum.SelStart = 0
txtPageNum.SelLength = Len(txtPageNum.Text)
End Sub
Private Sub txtPageNum_KeyPress(KeyAscii As Integer)
If (Chr(KeyAscii) < "0" Or Chr(KeyAscii) > "9") And KeyAscii <> 8 And KeyAscii <> 13 Then KeyAscii = 0
If KeyAscii = 13 Then cmdGoTo_Click
End Sub
Private Sub vsl_Change()
picPreview.Top = picPreview.Top - (vsl.Value - oldV) * IIf((picPreview.Height - picH) > 32767, 10, 1)
oldV = vsl.Value
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -