📄 frmqueryprint.frm
字号:
picPreview.ScaleMode = 6
iPercent = 100
tbButton.Buttons(2).Visible = bShowAbout
' 初始化数据
oldV = 0
oldH = 0
' 将每一列记录的基本信息存入数组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 rsFlag = bpQueryEx Then
With frmQueryGrid
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
iCount = Remark.Count + 3
For i = 0 To iCount - 1
Next i
End Sub
Private Sub Form_Resize()
' 当窗口变化时,重新设置滚动条位置,picBack位置
picBack.Top = cbTool.Height + 60
picBack.Left = 60
picBack.Width = Me.Width - 250
picBack.Height = Me.Height - cbTool.Height - 520
' 200表示picPreview在fraPic中显示时的上下边距,80表示左右边距,并扣除滚动条所占位置
picH = picBack.Height - 200 - 300
picW = picBack.Width - 80 - 350
Call ResizePic
End Sub
Private Sub hsl_Change()
picPreview.Left = picPreview.Left - (hsl.Value - oldH) * IIf((picPreview.Width - picW) > 32767, 10, 1)
Call DrawPage
oldH = hsl.Value
End Sub
Private Sub tbTool_ButtonClick(ByVal Button As MSComctlLib.Button)
Select Case Button.Key
Case "first"
intPartIndex = 1
pageNum = 1
PrintPreview iPercent
Case "previous"
If intPartIndex > 1 Then
intPartIndex = intPartIndex - 1
Else
intPartIndex = intPartCount
End If
If pageNum <> 1 And intPartIndex = intPartCount Then pageNum = pageNum - 1 '当前页号减1
PrintPreview iPercent
Case "next"
If intPartIndex < intPartCount Then
intPartIndex = intPartIndex + 1
Else
intPartIndex = 1
End If
If pageNum <> pageCount And intPartIndex = 1 Then pageNum = pageNum + 1 '当前页数加1
PrintPreview iPercent
Case "last"
intPartIndex = intPartCount
pageNum = pageCount
PrintPreview iPercent
Case "zoomout"
If cboScale.ListIndex = cboScale.ListCount - 1 Then Exit Sub
cboScale.ListIndex = cboScale.ListIndex + 1
Case "zoomin"
If cboScale.ListIndex = 0 Then Exit Sub
cboScale.ListIndex = cboScale.ListIndex - 1
End Select
End Sub
Private Sub txtPage_GotFocus()
txtPage.SelStart = 0
txtPage.SelLength = Len(txtPage.Text)
End Sub
Private Sub txtPart_GotFocus()
txtPart.SelStart = 0
txtPart.SelLength = Len(txtPart.Text)
End Sub
Private Sub txtPage_KeyPress(KeyAscii As Integer)
Dim strPercent As String
If (Chr(KeyAscii) < "0" Or Chr(KeyAscii) > "9") And KeyAscii <> 8 And KeyAscii <> 13 Then KeyAscii = 0
If KeyAscii = 13 Then
If txtPage.Text = "" Then Exit Sub
If CInt(txtPage.Text) < 1 Or CInt(txtPage.Text) > pageCount Then
MsgBox "此页码不存在!", vbOKOnly + vbInformation
Exit Sub
End If
strPercent = cboScale.List(cboScale.ListIndex)
strPercent = Left(strPercent, Len(strPercent) - 1)
iPercent = CLng(strPercent)
intPartIndex = 1
pageNum = CInt(txtPage.Text)
PrintPreview iPercent
End If
End Sub
Private Sub vsl_Change()
picPreview.Top = picPreview.Top - (vsl.Value - oldV) * IIf((picPreview.Height - picH) > 32767, 10, 1)
Call DrawPage
oldV = vsl.Value
End Sub
Private Sub tbButton_ButtonClick(ByVal Button As MSComctlLib.Button)
Select Case Button.Key
Case "quit"
Unload Me
Case "about"
' Set picPreview.Font = liPrint(0).Font
' Set Printer.Font = liPrint(0).Font
' picPreview.Line (0, 5)-(Printer.TextWidth(liPrint(0).Text), 5), vbBlack
' picPreview.Line (0, 8)-(picPreview.TextWidth(liPrint(0).Text), 8), vbBlack
' picPreview.CurrentX = 0
' picPreview.CurrentY = 10
' picPreview.Print liPrint(0).Text
modPubFun.AboutInfo
End Select
End Sub
Private Sub tbPrint_ButtonClick(ByVal Button As MSComctlLib.Button)
'/*使用自己的对话框打印,气死它
Dim strPercent As String
Select Case Button.Key
Case "print"
frmQuerySetPrint.Show vbModal, Me
If Not bIsChange Then Exit Sub
Me.MousePointer = 11
' 设置打印页码范围
Select Case intRange
Case 1
intStart = 1
intEnd = pageCount
Case 3
If intStart = 0 Then intStart = 1
End Select
' 根据打印范围的选择来设置当前页码或打印页码范围
Select Case intRange
Case 1, 3
pageNum = intStart
Case 2
intStart = pageNum
intEnd = pageNum
End Select
intPartIndex = 1
' 将记录指针移至被选择范围的第一条记录
' 循环调用PrintReport打印报表
bCancle = False
fraPb.Left = (picBack.Width - fraPb.Width) \ 2
fraPb.Top = (picBack.Height - fraPb.Height) \ 2
fraPb.Visible = True
DoEvents
pbPrint.Max = intEnd
pbPrint.Min = intStart - 1
pbPrint.Value = intStart - 1
Do While pageNum <= intEnd 'rstReport.EOF
rstReport.MoveFirst
rstReport.Move (pageNum - 1) * rowNum
PrintReport 100
If bCancle Then
Printer.KillDoc
Exit Do
End If
DoEvents
If intPartIndex < intPartCount Then
intPartIndex = intPartIndex + 1
Else
pbPrint.Value = pageNum
pageNum = pageNum + 1
intPartIndex = 1
End If
Loop
fraPb.Visible = False
' 设置当前页为打印的最后页,重新预览当前页
pageNum = intEnd
PrintPreview iPercent
Me.MousePointer = 0
Case "export"
' '/*导出数据到其它地方
' frmExport.Show 1, Me
Case "set"
intRange = 1
intStart = 1
intEnd = pageCount
' 显示打印设置窗口
frmQueryOption.Show vbModal
If Not bIsChange Then Exit Sub
PageAnalyze
If pageNum > pageCount Then pageNum = 1
' 根据重新设置的打印参数预览当前页
PrintPreview iPercent
End Select
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -