⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 frmpreview.frm

📁 国防工业部VB高级编程源码
💻 FRM
📖 第 1 页 / 共 2 页
字号:
VERSION 5.00
Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "COMDLG32.OCX"
Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCTL.OCX"
Begin VB.Form FrmPreview 
   BackColor       =   &H8000000C&
   BorderStyle     =   1  'Fixed Single
   Caption         =   "打印预览"
   ClientHeight    =   7335
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   9915
   Icon            =   "FrmPreview.frx":0000
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   ScaleHeight     =   7335
   ScaleWidth      =   9915
   StartUpPosition =   2  '屏幕中心
   Begin VB.TextBox Text1 
      BackColor       =   &H80000003&
      BorderStyle     =   0  'None
      Height          =   105
      Left            =   0
      TabIndex        =   4
      Top             =   480
      Width           =   60
   End
   Begin MSComctlLib.ImageList Imglst 
      Left            =   3960
      Top             =   1800
      _ExtentX        =   1005
      _ExtentY        =   1005
      BackColor       =   -2147483643
      ImageWidth      =   24
      ImageHeight     =   23
      MaskColor       =   12632256
      _Version        =   393216
      BeginProperty Images {2C247F25-8591-11D1-B16A-00C0F0283628} 
         NumListImages   =   4
         BeginProperty ListImage1 {2C247F27-8591-11D1-B16A-00C0F0283628} 
            Picture         =   "FrmPreview.frx":030A
            Key             =   "open"
            Object.Tag             =   "open"
         EndProperty
         BeginProperty ListImage2 {2C247F27-8591-11D1-B16A-00C0F0283628} 
            Picture         =   "FrmPreview.frx":0986
            Key             =   ""
         EndProperty
         BeginProperty ListImage3 {2C247F27-8591-11D1-B16A-00C0F0283628} 
            Picture         =   "FrmPreview.frx":0CA2
            Key             =   "large"
            Object.Tag             =   "large"
         EndProperty
         BeginProperty ListImage4 {2C247F27-8591-11D1-B16A-00C0F0283628} 
            Picture         =   "FrmPreview.frx":0FBE
            Key             =   "small"
            Object.Tag             =   "small"
         EndProperty
      EndProperty
   End
   Begin MSComctlLib.Toolbar TBar 
      Align           =   1  'Align Top
      Height          =   525
      Left            =   0
      TabIndex        =   3
      Top             =   0
      Width           =   9915
      _ExtentX        =   17489
      _ExtentY        =   926
      ButtonWidth     =   820
      ButtonHeight    =   767
      Appearance      =   1
      ImageList       =   "Imglst"
      _Version        =   393216
      BeginProperty Buttons {66833FE8-8583-11D1-B16A-00C0F0283628} 
         NumButtons      =   5
         BeginProperty Button1 {66833FEA-8583-11D1-B16A-00C0F0283628} 
            Key             =   "open"
            Description     =   "open"
            Object.ToolTipText     =   "打开"
            ImageIndex      =   1
         EndProperty
         BeginProperty Button2 {66833FEA-8583-11D1-B16A-00C0F0283628} 
            Style           =   3
         EndProperty
         BeginProperty Button3 {66833FEA-8583-11D1-B16A-00C0F0283628} 
            Key             =   "large"
            Description     =   "large"
            Object.ToolTipText     =   "放大"
            ImageIndex      =   3
         EndProperty
         BeginProperty Button4 {66833FEA-8583-11D1-B16A-00C0F0283628} 
            Key             =   "small"
            Description     =   "small"
            Object.ToolTipText     =   "缩小"
            ImageIndex      =   4
         EndProperty
         BeginProperty Button5 {66833FEA-8583-11D1-B16A-00C0F0283628} 
            Key             =   "normal"
            Description     =   "normal"
            Object.ToolTipText     =   "正常大小"
            ImageIndex      =   2
         EndProperty
      EndProperty
   End
   Begin MSComDlg.CommonDialog CDlgFile 
      Left            =   1920
      Top             =   840
      _ExtentX        =   847
      _ExtentY        =   847
      _Version        =   393216
   End
   Begin VB.HScrollBar HBForm 
      Height          =   255
      Left            =   3960
      Max             =   3000
      TabIndex        =   2
      Top             =   5880
      Width           =   1335
   End
   Begin VB.VScrollBar VBForm 
      Height          =   1455
      Left            =   6240
      Max             =   3000
      TabIndex        =   1
      Top             =   1680
      Width           =   255
   End
   Begin VB.PictureBox PicPreview 
      Appearance      =   0  'Flat
      AutoRedraw      =   -1  'True
      BackColor       =   &H80000005&
      ForeColor       =   &H80000008&
      Height          =   2775
      Index           =   1
      Left            =   1920
      ScaleHeight     =   2745
      ScaleWidth      =   2505
      TabIndex        =   0
      Top             =   1440
      Width           =   2535
   End
   Begin VB.Menu menuFile 
      Caption         =   "文件(&F)"
      Begin VB.Menu menuFileOpen 
         Caption         =   "打开(&O)..."
      End
      Begin VB.Menu menuFileClose 
         Caption         =   "关闭(&C)"
      End
      Begin VB.Menu menuFileBar 
         Caption         =   "-"
      End
      Begin VB.Menu menuFileExit 
         Caption         =   "退出(&X)"
      End
   End
   Begin VB.Menu menuPView 
      Caption         =   "预览(&P)"
      Begin VB.Menu menuPViewLarge 
         Caption         =   "放大(&+)"
      End
      Begin VB.Menu menuPViewSmall 
         Caption         =   "缩小(&-)"
      End
      Begin VB.Menu menuPViewProportion 
         Caption         =   "预览比例..."
      End
      Begin VB.Menu menuPViewNormal 
         Caption         =   "正常大小(&N)"
      End
   End
End
Attribute VB_Name = "FrmPreview"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Dim m_strFileName As String
'保存打开文件名
Dim m_strFileContent As String
'保存文件文本
Dim m_lgWindowHeight As Long
'屏幕显示高度
Dim m_lgWindowWidth As Long
'屏幕显示宽度
Dim m_lgA4Height As Long
Dim m_lgA4Width As Long
'A4纸张的大小
Dim m_sngProportion As Single
'预览比例
Dim m_lgA4TopSpace As Long
Dim m_lgA4SideSpace As Long
'页面距
Dim m_sngMarginTop As Single
Dim m_sngMarginSide As Single
'页边距
Dim m_sngFontSize As Single
'字体大小
Dim m_intPageCount As Integer
'页数
Dim m_intHPage As Integer
Dim m_intVPage As Integer
'多页排列显示参数
Dim m_intHBBak As Integer
Dim m_intVBBak As Integer
'记录滚动条位置

Private Sub Form_Load()
    '作初始化工作
    '纸张大小的设置
    m_lgA4Height = 297 * 56
    m_lgA4Width = 210 * 56
    m_sngProportion = 1
    
    m_lgA4TopSpace = 1000
    m_lgA4SideSpace = 1000
    m_sngMarginTop = 25.4 * 56
    m_sngMarginSide = 31.7 * 56
    m_sngFontSize = 10.5
    
    m_intPageCount = 1
    
    '界面元素的初始化
    PicPreview(m_intPageCount).Visible = False
    HBForm.Visible = False
    VBForm.Visible = False
    menuPView.Enabled = False
    menuFileClose.Enabled = False
    
    VBForm.Max = 3000
    HBForm.Max = 3000
    VBForm.Min = 0
    HBForm.Min = 0
    VBForm.SmallChange = 100
    VBForm.LargeChange = 500
    HBForm.SmallChange = 100
    HBForm.LargeChange = 500
    VBForm.Value = 0
    HBForm.Value = 0
    m_intVBBak = VBForm.Value
    m_intHBBak = HBForm.Value
    
    TBar.Buttons("small").Value = tbrUnpressed
    TBar.Buttons("large").Value = tbrUnpressed
    TBar.Buttons("normal").Value = tbrUnpressed
    TBar.Buttons("small").Enabled = False
    TBar.Buttons("large").Enabled = False
    TBar.Buttons("normal").Enabled = False
    
    
End Sub

Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
    If Button = 2 And menuPView.Enabled = True Then
    '检查鼠标右键是否被单击
        PopupMenu menuPView
    '弹出式菜单弹出
    End If
        
End Sub


Private Sub HBForm_Change()
    Dim i As Integer
    Dim sngR As Single
    Dim lgPosition As Long
    '水平滚动条移动计算
    sngR = (HBForm.Value - m_intHBBak) / HBForm.Max
    lgPosition = ((PicPreview(1).Width + m_lgA4SideSpace * m_sngProportion) * m_intHPage + m_lgA4SideSpace * m_sngProportion - HBForm.Width) * sngR
    m_intHBBak = HBForm.Value
    
    For i = 1 To m_intPageCount
        PicPreview(i).Left = PicPreview(i).Left - lgPosition
    Next
   Text1.SetFocus
End Sub

Private Sub menuFileClose_Click()
    Dim i As Integer
    '文件关闭,页面不显示
    PicPreview(1).Visible = False
    For i = 2 To m_intPageCount
        Unload PicPreview(i)
    Next
    '相应界面元素也要改变
    HBForm.Visible = False
    VBForm.Visible = False
    menuPView.Enabled = False
    menuFileClose.Enabled = False
    menuFileOpen.Enabled = True
    TBar.Buttons("small").Enabled = False
    TBar.Buttons("large").Enabled = False
    TBar.Buttons("normal").Enabled = False
    TBar.Buttons("open").Enabled = True

End Sub

Private Sub menuFileExit_Click()
    End
    '程序结束
End Sub

Private Sub menuFileOpen_Click()
   '打开文件
   m_strFileName = ""
   On Error GoTo ErrHandler1
   '设置过滤器。
   CDlgFile.Filter = "All Files (*.*)|*.*|Text Files (*.txt)|*.txt"
   '指定缺省过滤器。
   CDlgFile.FilterIndex = 2

   '显示“打开”对话框。
   CDlgFile.ShowOpen
   
   '保存打开文件名字
   
   m_strFileName = CDlgFile.FileName

    
   '调用Text文件打开程序
   OpenTextFile
   '界面元素改变
   Exit Sub

ErrHandler1:
'用户按“取消”按钮。
   m_strFileName = ""
End Sub

Sub OpenTextFile()
   Dim strLine As String
   Dim fso As FileSystemObject
   Dim fl As File
   m_strFileContent = ""
   If m_strFileName <> "" Then
    '判断文件的大小,如果太大了则打开
    Set fso = CreateObject("scripting.filesystemobject")
    Set fl = fso.GetFile(m_strFileName)
     If fl.Size < 10000 Then  '文件小于10K
    '使用I/O函数打开TEXT文件,把文本保持到m_strFileContent里面
         Open m_strFileName For Input As #1
         Do While EOF(1) <> True
             Line Input #1, strLine
             m_strFileContent = m_strFileContent + strLine + Chr(13) & Chr(10)
         Loop
         Close #1
     '界面改变
         menuPView.Enabled = True
         menuFileClose.Enabled = True
         menuFileOpen.Enabled = False
        TBar.Buttons("small").Value = tbrUnpressed
        TBar.Buttons("large").Value = tbrUnpressed
        TBar.Buttons("normal").Value = tbrPressed
        TBar.Buttons("small").Enabled = True
        TBar.Buttons("large").Enabled = True
        TBar.Buttons("normal").Enabled = True
        TBar.Buttons("open").Enabled = False

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -