打印机为 EPSON LQ-300K
程序里设置printter.Height及Printer.Width为希望值,但不起作用,printter.Height及Printer.Width始终是一个默认值,无法改变!
难道要设置Printer.PaperSize?
请教如何才能设置打印纸张大小?
程序里设置printter.Height及Printer.Width为希望值,但不起作用,printter.Height及Printer.Width始终是一个默认值,无法改变!
难道要设置Printer.PaperSize?
请教如何才能设置打印纸张大小?
解决方案 »
- 小弟刚学VB,想知道哪有MSDN下载
- 急!!mschart为何不能显示access?
- 在线请教,VB中如何读取文本数据库中的记录数据
- 软件开发小组找项目(北京)
- 如何制作winpim的界面???
- 请教如何在一堆的WPS\WORD\EXEL\TXT文件中找出几个特定的文字?!!!
- 如何实现MSFlexGrid拖放所选行?或者如何实现组合排序(先按第一列排序再按第二列排序)?
- 高分求教:关于VB安装包中的setup.lst文件的问题?
- 哪里有QQ的源码?
- 在vb中如何调用access实现数据库的压缩
- 用access得query按照要求排序生成一个table,不知为什么生成的table排序总是随机在变!!
- 在vb中用web组件如何获得网页源代码
另外,"Printer first Grid"控件附带的鼠标滚轮绑定方法,可使指定窗体中的所有DataGrid、MSFlexGrid、MSHFlexGrid等控件轻松的支持鼠标滚轮功能,不需安装任何驱动程序,即可支持所有带滚轮的鼠标。下载地址(内附演示程序): http://lpcsoft.itdrp.com/
不是打印机属性
是打印机界面windows的第一个大菜单里面
服务器属性---设置
打印机属性---调用
'*Constants used in the DevMode structure
Private Const CCHDEVICENAME = 32
Private Const CCHFORMNAME = 32'*Constants for NT security
Private Const STANDARD_RIGHTS_REQUIRED = &HF0000
Private Const PRINTER_ACCESS_ADMINISTER = &H4
Private Const PRINTER_ACCESS_USE = &H8
Private Const PRINTER_ALL_ACCESS = (STANDARD_RIGHTS_REQUIRED Or PRINTER_ACCESS_ADMINISTER Or PRINTER_ACCESS_USE)'*Constants used to make changes to the values contained in the DevMode
Private Const DM_MODIFY = 8
Private Const DM_COPY = 2
Private Const DM_DUPLEX = &H1000&
Private Const DMDUP_SIMPLEX = 1
Private Const DMDUP_VERTICAL = 2
Private Const DMDUP_HORIZONTAL = 3Private Const DM_IN_BUFFER As Long = 8
Private Const DM_OUT_BUFFER As Long = 2
Private Const DM_ORIENTATION As Long = &H1
Private Const DM_PAPERSIZE = &H2&
Private Const DM_PAPERWIDTH = &H8&
Private Const DM_PAPERLENGTH = &H4&Private Type DEVMODE
dmDeviceName As String * 32
dmSpecVersion As Integer
dmDriverVersion As Integer
dmSize As Integer
dmDriverExtra As Integer
dmFields As Long
dmOrientation As Integer
dmPaperSize As Integer
dmPaperLength As Integer
dmPaperWidth As Integer
dmScale As Integer
dmCopies As Integer
dmDefaultSource As Integer
dmPrintQuality As Integer
dmColor As Integer
dmDuplex As Integer
dmYResolution As Integer
dmTTOption As Integer
dmCollate As Integer
dmFormName As String * 32
dmUnusedPadding As Integer
dmBitsPerPel As Integer
dmPelsWidth As Long
dmPelsHeight As Long
dmDisplayFlags As Long
dmDisplayFrequency As Long
End TypePrivate Type PRINTER_DEFAULTS
pDataType As String
pDevMode As Long
DesiredAccess As Long
End TypePrivate Type PRINTER_INFO_2
pServerName As Long
pPrinterName As Long
pShareName As Long
pPortName As Long
pDriverName As Long
pComment As Long
pLocation As Long
pDevMode As Long
pSepFile As Long
pPrintProcessor As Long
pDataType As Long
pParameters As Long
pSecurityDescriptor As Long
Attributes As Long
Priority As Long
DefaultPriority As Long
StartTime As Long
UntilTime As Long
status As Long
cJobs As Long
AveragePPM As Long
End Type'*------DECLARATIONS
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" _
(hpvDest As Any, hpvSource As Any, _
ByVal cbCopy As Long)Private Declare Function OpenPrinter Lib "winspool.drv" Alias "OpenPrinterA" _
(ByVal pPrinterName As String, _
phPrinter As Long, pDefault As Any) As LongPrivate Declare Function ClosePrinter Lib "winspool.drv" _
(ByVal hPrinter As Long) As LongPrivate Declare Function DocumentProperties Lib "winspool.drv" Alias "DocumentPropertiesA" _
(ByVal hWnd As Long, ByVal hPrinter As Long, _
ByVal pDeviceName As String, pDevModeOutput As Any, _
pDevModeInput As Any, ByVal fMode As Long) As LongPrivate Declare Function GetPrinter Lib "winspool.drv" Alias "GetPrinterA" _
(ByVal hPrinter As Long, ByVal level As Long, _
pPrinter As Any, ByVal cbBuf As Long, pcbNeeded As Long) As LongPrivate Declare Function SetPrinter Lib "winspool.drv" Alias "SetPrinterA" _
(ByVal hPrinter As Long, ByVal level As Long, _
pPrinter As Any, ByVal Command As Long) As LongPrivate Sub Command1_Click()
Dim uu As Boolean
If Printer.PaperSize <> 9 Then
uu = mySetPrinter(Printer.DeviceName, 1, 9, 0, 0)
Printer.EndDoc
End If
End SubPublic Function mySetPrinter(prnName As String, Optional eOrientation As Integer, Optional iDmpaper As Integer, Optional iDmpaperLength As Single, Optional iDmpaperWidth As Single) As BooleanDim bDevMode() As Byte
Dim bPrinterInfo2() As Byte
Dim hPrinter As Long
Dim lResult As Long
Dim nSize As Long
Dim sPrnName As StringDim dm As DEVMODE
Dim olddm As DEVMODE
Dim pd As PRINTER_DEFAULTS
Dim pi2 As PRINTER_INFO_2 On Error GoTo err_proc
sPrnName = prnName
pd.DesiredAccess = PRINTER_ALL_ACCESS
If OpenPrinter(sPrnName, hPrinter, pd) Then
Call GetPrinter(hPrinter, 2&, 0&, 0&, nSize)
ReDim bPrinterInfo2(1 To nSize) As Byte
lResult = GetPrinter(hPrinter, 2, bPrinterInfo2(1), nSize, nSize)
Call CopyMemory(pi2, bPrinterInfo2(1), Len(pi2))
nSize = DocumentProperties(0&, hPrinter, sPrnName, 0&, 0&, 0)
ReDim bDevMode(1 To nSize)
If pi2.pDevMode Then
Call CopyMemory(bDevMode(1), ByVal pi2.pDevMode, Len(dm))
Else
Call DocumentProperties(0&, hPrinter, sPrnName, bDevMode(1), 0&, DM_OUT_BUFFER)
End If
Call CopyMemory(dm, bDevMode(1), Len(dm))
Call CopyMemory(olddm, bDevMode(1), Len(olddm))
With dm
If eOrientation <> 0 Then
.dmOrientation = eOrientation
.dmFields = DM_ORIENTATION
End If
If iDmpaper <> 0 And iDmpaper <> vbPRPSUser Then
.dmPaperSize = iDmpaper
.dmFields = DM_PAPERSIZE
End If
If iDmpaper = vbPRPSUser Then
.dmFields = DM_PAPERLENGTH Or DM_PAPERWIDTH
.dmPaperLength = iDmpaperLength
.dmPaperWidth = iDmpaperWidth
End If
End With
Call CopyMemory(bDevMode(1), dm, Len(dm))
Call DocumentProperties(0&, hPrinter, sPrnName, _
bDevMode(1), bDevMode(1), DM_IN_BUFFER Or _
DM_OUT_BUFFER)
pi2.pDevMode = VarPtr(bDevMode(1))
lResult = SetPrinter(hPrinter, 2, pi2, 0&)
Call ClosePrinter(hPrinter)
mySetPrinter = True
Else
mySetPrinter = False
End If
Exit Function
err_proc:
mySetPrinter = False
End Function
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 英吋。"
PaperStyle(vbPRPSLedger) = "分類帳, 17 x 11 英吋。"
PaperStyle(vbPRPSLegal) = "法律檔案, 8 1/2 x 14 英吋。"
PaperStyle(vbPRPSStatement) = "宣告書,5 1/2 x 8 1/2 英吋。"
PaperStyle(vbPRPSExecutive) = "行政檔案,7 1/2 x 10 1/2 英吋。"
PaperStyle(vbPRPSA3) = "A3, 297 x 420 公厘"
PaperStyle(vbPRPSA4) = "A4, 210 x 297 公厘"
PaperStyle(vbPRPSA4Small) = "A4小號, 210 x 297 公厘"
PaperStyle(vbPRPSA5) = "A5, 148 x 210 公厘"
PaperStyle(vbPRPSB4) = "B4, 250 x 354 公厘"
PaperStyle(vbPRPSB5) = "B5, 182 x 257 公厘"
PaperStyle(vbPRPSFolio) = "對開本, 8 1/2 x 13 英吋。"
PaperStyle(vbPRPSQuarto) = "四開本, 215 x 275 公厘。"
PaperStyle(vbPRPS10x14) = "10 x 14 英吋。"
PaperStyle(vbPRPS11x17) = "11 x 17 英吋。"
PaperStyle(vbPRPSNote) = "便條,8 1/2 x 11 英吋。"
PaperStyle(vbPRPSEnv9) = "#9 信封, 3 7/8 x 8 7/8 英吋。"
PaperStyle(vbPRPSEnv10) = "#10 信封, 4 1/8 x 9 1/2 英吋。"
PaperStyle(vbPRPSEnv11) = "#11 信封, 4 1/2 x 10 3/8 英吋。"
PaperStyle(vbPRPSEnv12) = "#12 信封, 4 1/2 x 11 英吋。"
PaperStyle(vbPRPSEnv14) = "#14 信封, 5 x 11 1/2 英吋。"
PaperStyle(vbPRPSCSheet) = "C 尺寸工作單"
PaperStyle(vbPRPSDSheet) = "D 尺寸工作單"
PaperStyle(vbPRPSESheet) = "E 尺寸工作單"
PaperStyle(vbPRPSEnvDL) = "DL 型信封, 110 x 220 公厘"
PaperStyle(vbPRPSEnvC3) = "C3 型信封, 324 x 458 公厘"
PaperStyle(vbPRPSEnvC4) = "C4 型信封, 229 x 324 公厘"
PaperStyle(vbPRPSEnvC5) = "C5 型信封, 162 x 229 公厘"
PaperStyle(vbPRPSEnvC6) = "C6 型信封, 114 x 162 公厘"
PaperStyle(vbPRPSEnvC65) = "C65 型信封,114 x 229 公厘"
PaperStyle(vbPRPSEnvB4) = "B4 型信封, 250 x 353 公厘"
PaperStyle(vbPRPSEnvB5) = "B5 型信封,176 x 250 公厘"
PaperStyle(vbPRPSEnvB6) = "B6 型信封, 176 x 125 公厘"
PaperStyle(vbPRPSEnvItaly) = "信封, 110 x 230 公厘"
PaperStyle(vbPRPSEnvMonarch) = "信封大王, 3 7/8 x 7 1/2 英吋。"
PaperStyle(vbPRPSEnvPersonal) = "信封, 3 5/8 x 6 1/2 英吋。"
PaperStyle(vbPRPSFanfoldUS) = "U.S. 標準複寫簿, 14 7/8 x 11 英吋。"
PaperStyle(vbPRPSFanfoldStdGerman) = "德國標準複寫簿, 8 1/2 x 12 英吋。"
PaperStyle(vbPRPSFanfoldLglGerman) = "德國法律複寫簿, 8 1/2 x 13 英吋。"
End Sub
Private Sub Form_Load()
Dim TempPrint As Printer
'列出本機可使用的所有印表機
For Each TempPrint In Printers
List1.AddItem TempPrint.DeviceName
Next '執行把紙張格式說明放入陣列中的自訂副程式
GotPaperStyle
End Sub
Private Sub List1_Click()
'依 List1 Item 設定 DefaultPrinter,並依 DefaultPrinter 找出可支援的紙
張格式。
If List1.ListIndex >= 0 Then
'設定 DefaultPrinter副程式
SetDefaultPrinter List1.List(List1.ListIndex)
'找出支援紙張格式副程式
WhatPaperCanUse
End If
End Sub
'設定 DefaultPrinter副程式
Private Sub SetDefaultPrinter(ByVal DName As String)
For Each XPrint In Printers
If XPrint.DeviceName = DName Then
Set Printer = XPrint
Exit For
End If
Next
End Sub
'找出支援紙張格式副程式
Private Sub WhatPaperCanUse()
Dim I As Long On Error Resume Next
List2.Clear For I = LBound(PaperStyle) To UBound(PaperStyle)
'清除錯誤碼
Err.Number = 0
'本程式是先設定紙張格式,再觀察是否有誤,只有無錯誤者才加入 List2 中
Printer.PaperSize = I
Select Case Err.Number
Case 0
List2.AddItem PaperStyle(I)
List2.ItemData(List2.NewIndex) = I
Case 380
Case Else
MsgBox Err.Description, vbOKOnly, "錯誤代號:" & Err.Number
Exit For
End Select
Next
End Sub
'依紙張格式顯示紙張長寬
Private Sub List2_Click()
If List2.ListIndex >= 0 Then
Printer.PaperSize = List2.ItemData(List2.ListIndex)
Label4.Caption = Printer.ScaleX(Printer.Width, Printer.ScaleMode,vbMillimeters)
Label6.Caption = Printer.ScaleY(Printer.Height, Printer.ScaleMode,vbMillimeters)
'因為不要印出,所以把列印序列殺掉。
Printer.KillDoc
End If
End Sub
点击打印按钮立刻用默认的打印机开始打印,不弹出设定打印机、纸张的对话框.小弟想问
一下在VB中怎样指定纸张为前面设置的自定义纸张,小弟的系统为WINXP.望高手不吝赐教,小弟不胜感激.
datareport.show
之后会出现预览报表,先不要打印,先点左上角的打印机,选择需要的纸型后再打印,一切正常。