设为首页收藏本站Access中国

Office中国论坛/Access中国论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

返回列表 发新帖
查看: 2938|回复: 1
打印 上一主题 下一主题

[推荐]如何更改印表機的紙張大小設定

[复制链接]
跳转到指定楼层
1#
发表于 2003-11-24 22:57:00 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
如何更改印表機的紙張大小設定

--------------------------------------------------------------------------------

问:
因為我的專案須要很多種報表格式 如 A4,LETTER SIZE,我使用 VB的 PRINTER.PAPERSIZE 去更改設定但是沒有作用  !!!!想請教各位先進,有那一個 C++ OR API OR VB 指令可以動態設定印表機的狀態。

答:
你不需要 C++ or API ,你只須要在 VB 裏做出正確的設定,一定可以用 Printer.PaperSize 去更改紙張設定,而所謂正確設定,應該包含下列幾件事:
Set Default Printer 的動作要正確,如 VB 說明:
如果用Printers 集合物件來確定某一特定印表機,如 Printers(3),則只能存取唯讀屬性。如果想存取個別印表機的可讀寫屬性,首先要使那個印表機成為應用程式的預設印表機。
你可以參考下面範例 SetDefaultPrinter 的作法。
VB Printer 物件共支援 41 項紙張設定,連 UserType 共 42 項,但並不是每個印表機驅動程式都支援全部的紙張格式,所以在設定紙張格式前,你必須先測試目前 DefaultPrinter 能使用的紙張格式,請參考下面範例的 WhatPaperCanUse 副程式。
許多 VB 物件與電腦週邊設備的溝通,如果使用錯誤處理程序,也就是不管週邊支不支援,先加以驅動,再依傳回訊息處理,就可以不需使用 API 或其他語言的物件,在VB 內把問題解決掉。
此外比必須注意,當你改變了印表機 Height 和 Width 屬性設定時會自動將 PaperSize 設定為 vbPRPSUser(使用者自訂)。
'--------------------  印表機設定範例開始  --------------------------
VERSION 5.00
Begin VB.Form frmPrinterSet
   Caption         =   "印表機設定表單"
   ClientHeight    =   4245
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   6210
   LinkTopic       =   "Form1"
   ScaleHeight     =   4245
   ScaleWidth      =   6210
   StartUpPosition =   3  '系統預設值
   Begin VB.ListBox List2
      Height          =   1860
      Left            =   3000
      TabIndex        =   3
      Top             =   840
      Width           =   2895
   End
   Begin VB.ListBox List1
      Height          =   1860
      Left            =   240
      TabIndex        =   0
      Top             =   840
      Width           =   2535
   End
   Begin VB.Label Label6
      BackColor       =   &H80000009&
      BorderStyle     =   1  '單線固定
      Height          =   375
      Left            =   4200
      TabIndex        =   7
      Top             =   3600
      Width           =   1695
   End
   Begin VB.Label Label5
      Caption         =   "紙張高度(單位 釐米)"
      Height          =   375
      Left            =   4200
      TabIndex        =   6
      Top             =   3000
      Width           =   1695
   End
   Begin VB.Label Label4
      BackColor       =   &H80000009&
      BorderStyle     =   1  '單線固定
      Height          =   375
      Left            =   2160
      TabIndex        =   5
      Top             =   3600
      Width           =   1695
   End
   Begin VB.Label Label3
      Caption         =   "紙張寬度(單位 釐米)"
      Height          =   375
      Left            =   2160
      TabIndex        =   4
      Top             =   3000
      Width           =   1695
   End
   Begin VB.Label Label2
      Alignment       =   2  '靠中對齊
      Caption         =   "可使用紙張格式"
      Height          =   375
      Left            =   3360
      TabIndex        =   2
      Top             =   240
      Width           =   2175
   End
   Begin VB.Label Label1
      Alignment       =   2  '靠中對齊
      Caption         =   "印表機型號"
      Height          =   375
      Left            =   480
      TabIndex        =   1
      Top             =   240
      Width           =   2055
   End
End
Attribute VB_Name = "frmPrinterSet"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
'所有紙張型號的儲存陣列
Dim PaperStyle(1 To 41) As String
'印表機參照變數
Dim XPrint As Printer
'把所有 Printer 物件能支援的紙張格式說明放入陣列中
Private Sub GotPaperStyle()
    PaperStyle(vbPRPSLetter) = "信箋, 8 1/2 x 11 英吋。"
    PaperStyle(vbPRPSLetterSmall) = "小型信箋, 8 1/2 x 11 英吋。"
    PaperStyle(vbPRPSTabloid) = "小型報, 11 x 17
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享分享 分享淘帖 订阅订阅
2#
发表于 2003-11-29 22:58:00 | 只看该作者
晕,这么多,怎么用啊?
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|站长邮箱|小黑屋|手机版|Office中国/Access中国 ( 粤ICP备10043721号-1 )  

GMT+8, 2024-4-29 20:41 , Processed in 0.081457 second(s), 25 queries .

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表