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

📄 spool.frm

📁 很好的教程原代码!
💻 FRM
字号:
VERSION 5.00
Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "COMDLG32.OCX"
Begin VB.Form frmSpool 
   BorderStyle     =   4  'Fixed ToolWindow
   Caption         =   "Submit File to Print Spooler"
   ClientHeight    =   2115
   ClientLeft      =   1275
   ClientTop       =   1560
   ClientWidth     =   5490
   Icon            =   "SPOOL.frx":0000
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MinButton       =   0   'False
   PaletteMode     =   1  'UseZOrder
   ScaleHeight     =   2115
   ScaleWidth      =   5490
   ShowInTaskbar   =   0   'False
   Begin VB.ComboBox Combo1 
      Height          =   300
      Left            =   180
      Style           =   2  'Dropdown List
      TabIndex        =   4
      Top             =   1080
      Width           =   4395
   End
   Begin VB.CommandButton cmdClose 
      Cancel          =   -1  'True
      Caption         =   "退出"
      Height          =   315
      Left            =   3180
      TabIndex        =   6
      Top             =   1560
      Width           =   1395
   End
   Begin VB.CommandButton cmdPrint 
      Caption         =   "打印"
      Height          =   315
      Left            =   1560
      TabIndex        =   5
      Top             =   1560
      Width           =   1395
   End
   Begin VB.TextBox txtFile 
      Height          =   315
      Left            =   180
      TabIndex        =   1
      Text            =   "txtFile"
      Top             =   420
      Width           =   3975
   End
   Begin VB.CommandButton cmdFile 
      Caption         =   "..."
      Height          =   315
      Left            =   4200
      TabIndex        =   2
      Top             =   420
      Width           =   375
   End
   Begin MSComDlg.CommonDialog CommonDialog1 
      Left            =   4860
      Top             =   120
      _ExtentX        =   847
      _ExtentY        =   847
      _Version        =   393216
      CancelError     =   -1  'True
      DialogTitle     =   "Select File to Print"
   End
   Begin VB.Label Label2 
      AutoSize        =   -1  'True
      Caption         =   "可获得的打印机:"
      Height          =   180
      Left            =   240
      TabIndex        =   3
      Top             =   840
      Width           =   1440
   End
   Begin VB.Label Label1 
      AutoSize        =   -1  'True
      Caption         =   "要打印的文件:"
      Height          =   180
      Left            =   240
      TabIndex        =   0
      Top             =   180
      Width           =   1260
   End
End
Attribute VB_Name = "frmSpool"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
'
Private Sub cmdClose_Click()
    Unload Me
End Sub
'
Private Sub cmdFile_Click()
    With CommonDialog1
        '
        ' 设置对话框属性
        '
        .Flags = cdlOFNFileMustExist Or cdlOFNHideReadOnly
        .Filter = "Print Files (*.prn)|*.PRN|AllFiles (*.*)|*.*"
        '
        ' 获取文件名,允许用户选择取消
        '
        On Error Resume Next
        .ShowOpen
        '
        ' 将选择的文件名赋予文本框
        '
        If Err = 0 Then
           txtFile = .filename
        End If
    End With
End Sub
'
Private Sub cmdPrint_Click()
   Dim Submit As String
   Dim prn As Printer
   '
   ' 如果文件不存在则给予警告
   '
   Submit = UCase(Trim(txtFile))
   If Not IsFile(Submit) Then
      MsgBox "Can't find file: " & Submit, vbExclamation, "Error"
      Exit Sub
   End If
   '
   ' 向打印机提交文件
   '
   For Each prn In Printers
      If InStr(Combo1, prn.DeviceName) = 1 _
         And Right(Combo1, Len(prn.Port)) = prn.Port Then
            Call SpoolFile(Submit, prn.DeviceName)
            Exit For
      End If
   Next prn
End Sub
'
Private Sub Form_Initialize()
    '
    ' 确定是否已经安装打印机
    ' 如果没有安装则退出程序
    '
    If Printers.Count = 0 Then
        MsgBox "No printers are installed. Can't continue.", _
               vbCritical, "Fatal Error"
        End
    End If
End Sub
'
Private Sub Form_Load()
    Dim prn As Printer
    '
    ' 用可用的打印机填充组合框
    ' 并选择默认的打印机
    '
    For Each prn In Printers
       Combo1.AddItem prn.DeviceName & " on " & prn.Port
    Next prn
    '
    ' 选择默认的打印机
    '
    SelectDefaultPrinter Combo1
    '
    ' 窗体大小和位置;清空文本框
    '
    With Me
       .Width = Combo1.Width + Combo1.Left * 2 + _
                (.Width - Me.ScaleWidth)
       .Height = cmdPrint.Top + cmdPrint.Height + Label1.Top + _
                (.Height - .ScaleHeight)
       .Move (Screen.Width - .Width) \ 2, _
             (Screen.Height - .Height) \ 2
    End With
    txtFile = ""
End Sub


⌨️ 快捷键说明

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