📄 frmpreview.frm
字号:
'调用文件显示函数
PaperShow
Else
MsgBox "文件太大了!", vbInformation, "注意"
End If
End If
End Sub
Sub WindowSize()
m_lgWindowHeight = FrmPreview.ScaleHeight - TBar.Height
m_lgWindowWidth = FrmPreview.ScaleWidth
End Sub
Sub PaperShow()
'整个程序的核心所在
'页面的显示设计所需的变量
Dim lgPaperHeight As Long
Dim lgPaperWidth As Long
Dim lgSideSpace As Long
Dim lgTopSpace As Long
Dim lgMarginTop As Long
Dim lgMarginSide As Long
'打印的坐标变量
Dim lgXStart As Long
Dim lgYStart As Long
Dim lgXEnd As Long
Dim lgYEnd As Long
Dim lgCurX As Long
Dim lgCurY As Long
Dim lgBakX As Long
Dim lgBakY As Long
'对字符串操作的变量
Dim lgStringLen As Long
Dim strchar As String
'循环所需的变量
Dim i As Long
Dim j As Integer
Dim K As Integer
'设计鼠标指针为漏斗型
FrmPreview.MousePointer = 11
'计算页面显示的尺寸
lgPaperHeight = m_lgA4Height * m_sngProportion
lgPaperWidth = m_lgA4Width * m_sngProportion
lgTopSpace = m_lgA4TopSpace * m_sngProportion
lgSideSpace = m_lgA4SideSpace * m_sngProportion
lgMarginTop = m_sngMarginTop * m_sngProportion
lgMarginSide = m_sngMarginSide * m_sngProportion
'计算文字显示的位置范围
lgXStart = lgMarginSide
lgYStart = lgMarginTop
lgXEnd = lgPaperWidth - lgMarginSide
lgYEnd = lgPaperHeight - lgMarginTop
'开始打印文字
PicPreview(m_intPageCount).Height = lgPaperHeight
PicPreview(m_intPageCount).Width = lgPaperWidth
lgCurX = lgXStart
lgCurY = lgYStart
'文字循环打印的核心代码
lgStringLen = Len(m_strFileContent)
i = 1
Do
lgBakX = lgCurX
lgBakY = lgCurY
strchar = Mid(m_strFileContent, i, 1)
PicPreview(m_intPageCount).CurrentX = lgCurX
PicPreview(m_intPageCount).CurrentY = lgCurY
PicPreview(m_intPageCount).FontSize = m_sngFontSize * m_sngProportion
Select Case strchar
Case Chr(10) '回车换行
Case Chr(13)
PicPreview(m_intPageCount).Print
lgCurX = lgXStart
lgCurY = PicPreview(m_intPageCount).CurrentY
If lgCurY > lgYEnd Then
'翻页
TurnPage lgPaperHeight, lgPaperWidth
lgCurX = lgXStart
lgCurY = lgYStart
End If
Case Else '是字符
If PicPreview(m_intPageCount).CurrentX + Charlen(strchar) > lgXEnd Then
PicPreview(m_intPageCount).Print
lgCurX = lgXStart
lgCurY = PicPreview(m_intPageCount).CurrentY
If lgCurY > lgYEnd Then
TurnPage lgPaperHeight, lgPaperWidth
lgCurX = lgXStart
lgCurY = lgYStart
End If
lgBakX = lgCurX
lgBakY = lgCurY
PicPreview(m_intPageCount).CurrentX = lgCurX
PicPreview(m_intPageCount).CurrentY = lgCurY
End If
PicPreview(m_intPageCount).Print strchar
lgCurX = lgBakX + Charlen(strchar)
lgCurY = lgBakY
End Select
i = i + 1
Loop While i <= lgStringLen
'计算显示区域大小
WindowSize
'多页显示
Dim intHPage As Integer
Dim intVPage As Integer
intHPage = 1
intVPage = m_intPageCount
'计算多页显示的页数
intHPage = Int((m_lgWindowWidth - lgSideSpace) / (lgPaperWidth + lgSideSpace))
If intHPage = 0 Then
intHPage = 1
intVPage = m_intPageCount
ElseIf intHPage > 1 Then
intVPage = Int(m_intPageCount / intHPage)
If intVPage * intHPage <> m_intPageCount Then intVPage = intVPage + 1
End If
m_intHPage = intHPage
m_intVPage = intVPage
'垂直、水平滚动条的显示
If (lgPaperHeight + lgTopSpace) * intVPage + lgTopSpace > m_lgWindowHeight Then
VBForm.Left = m_lgWindowWidth - VBForm.Width
VBForm.Top = TBar.Height
VBForm.Height = m_lgWindowHeight - HBForm.Height
VBForm.Visible = True
Else
VBForm.Visible = False
End If
If (lgPaperWidth + lgSideSpace) * intHPage + lgSideSpace > m_lgWindowWidth Then
HBForm.Left = 0
HBForm.Top = m_lgWindowHeight - HBForm.Height + TBar.Height
HBForm.Width = m_lgWindowWidth - VBForm.Width
HBForm.Visible = True
Else
HBForm.Visible = False
End If
If VBForm.Visible = False Then HBForm.Width = m_lgWindowWidth
If HBForm.Visible = False Then VBForm.Height = m_lgWindowHeight
'各页面的显示
If (lgPaperWidth + lgSideSpace) * intHPage + lgSideSpace <= m_lgWindowWidth Then
j = 1
Do While j <= intVPage
i = 1
Do While i <= intHPage
K = intHPage * (j - 1) + i
If K > m_intPageCount Then GoTo Outdo
PicPreview(K).Top = lgTopSpace + TBar.Height
PicPreview(K).Left = lgSideSpace
PicPreview(K).Top = PicPreview(K).Top + (lgTopSpace + lgPaperHeight) * (j - 1)
PicPreview(K).Left = PicPreview(K).Left + (lgSideSpace + lgPaperWidth) * (i - 1)
i = i + 1
Loop
j = j + 1
Loop
Outdo:
For j = 1 To m_intPageCount
PicPreview(j).Visible = True
Next
Else '页面单列排列显示
For j = 1 To m_intPageCount
If VBForm.Visible Then
PicPreview(j).Top = lgTopSpace + TBar.Height
ElseIf HBForm.Visible Then
PicPreview(j).Top = (VBForm.Top - (lgPaperHeight + lgTopSpace) * j + lgTopSpace) / 2
Else
PicPreview(j).Top = (m_lgWindowHeight - (lgPaperHeight + lgTopSpace) * j + lgTopSpace) / 2
End If
PicPreview(j).Top = PicPreview(j).Top + (j - 1) * (lgPaperHeight + lgTopSpace)
If HBForm.Visible Then
PicPreview(j).Left = lgSideSpace
ElseIf VBForm.Visible Then
PicPreview(j).Left = (VBForm.Left - lgPaperWidth) / 2
Else
PicPreview(j).Left = (m_lgWindowWidth - lgPaperWidth) / 2
End If
'PicPreview(j).Line (lgXStart, lgYStart)-(lgXEnd, lgYEnd), , B
PicPreview(j).Visible = True
Next
End If
'滚动条位置
m_intHBBak = 0
m_intVBBak = 0
HBForm.Value = 0
HBForm.Value = 0
HBForm_Change
VBForm_Change
'鼠标指针改回箭头
FrmPreview.MousePointer = 0
End Sub
Function Charlen(strchar As String) As Long
'计算字符宽度
Charlen = PicPreview(m_intPageCount).TextWidth(strchar)
End Function
Sub TurnPage(lgHeight As Long, lgWidth As Long)
'翻页
m_intPageCount = m_intPageCount + 1
Load PicPreview(m_intPageCount)
PicPreview(m_intPageCount).Height = lgHeight
PicPreview(m_intPageCount).Width = lgWidth
PicPreview(m_intPageCount).AutoRedraw = True
End Sub
Private Sub menuPViewLarge_Click()
'页面放大
Dim i As Integer
If m_sngProportion < 3 Then
m_sngProportion = m_sngProportion + 0.5
For i = 2 To m_intPageCount
Unload PicPreview(i)
Next
PicPreview(1).Visible = False
PicPreview(1).Cls
m_intPageCount = 1
'调用页面显示过程
PaperShow
TBar.Buttons("large").Value = tbrPressed
TBar.Buttons("small").Value = tbrUnpressed
TBar.Buttons("normal").Value = tbrUnpressed
End If
End Sub
Private Sub menuPViewNormal_Click()
'页面正常比例显示
Dim i As Integer
If m_sngProportion <> 1 Then
m_sngProportion = 1
For i = 2 To m_intPageCount
Unload PicPreview(i)
Next
PicPreview(1).Visible = False
PicPreview(1).Cls
m_intPageCount = 1
'调用页面显示过程
PaperShow
TBar.Buttons("small").Value = tbrUnpressed
TBar.Buttons("large").Value = tbrUnpressed
TBar.Buttons("normal").Value = tbrPressed
End If
End Sub
Private Sub menuPViewProportion_Click()
'页面按照用户输入的比例显示
Dim sngR As Single
Dim i As Integer
Dim strInput As String
strInput = InputBox("请输入比例:是正常大小的?倍", "预览比例", m_sngProportion)
If IsNumeric(strInput) Then
sngR = CSng(strInput)
If sngR > 0.2 And sngR < 3 And sngR <> m_sngProportion Then
m_sngProportion = sngR
For i = 2 To m_intPageCount
Unload PicPreview(i)
Next
PicPreview(1).Visible = False
PicPreview(1).Cls
m_intPageCount = 1
PaperShow
TBar.Buttons("small").Value = tbrUnpressed
TBar.Buttons("large").Value = tbrUnpressed
TBar.Buttons("normal").Value = tbrPressed
If sngR = 1 Then
TBar.Buttons("normal").Value = tbrPressed
Else
TBar.Buttons("normal").Value = tbrUnpressed
End If
End If
End If
End Sub
Private Sub menuPViewSmall_Click()
'页面缩小显示
Dim i As Integer
If m_sngProportion > 0.2 Then
m_sngProportion = m_sngProportion / 2
For i = 2 To m_intPageCount
Unload PicPreview(i)
Next
PicPreview(1).Visible = False
PicPreview(1).Cls
m_intPageCount = 1
PaperShow
TBar.Buttons("small").Value = tbrPressed
TBar.Buttons("large").Value = tbrUnpressed
TBar.Buttons("normal").Value = tbrUnpressed
End If
End Sub
Private Sub TBar_ButtonClick(ByVal Button As MSComctlLib.Button)
'工具条按钮单击事件响应
Select Case Button.Key
Case Is = "open"
menuFileOpen_Click
Case Is = "large"
menuPViewLarge_Click
Case Is = "small"
menuPViewSmall_Click
Case Is = "normal"
menuPViewNormal_Click
End Select
TBar.Refresh
End Sub
Private Sub VBForm_Change()
'垂直滚动条滚动事件响应
Dim i As Integer
Dim sngR As Single
Dim lgPosition As Long
sngR = (VBForm.Value - m_intVBBak) / VBForm.Max
lgPosition = ((PicPreview(1).Height + m_lgA4TopSpace * m_sngProportion) * m_intVPage + m_lgA4TopSpace * m_sngProportion - VBForm.Height) * sngR
m_intVBBak = VBForm.Value
For i = 1 To m_intPageCount
PicPreview(i).Top = PicPreview(i).Top - lgPosition
Next
Text1.SetFocus
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -