• VB.NET条码机打印设置纸张大小的方法


    Imports System.Drawing.Printing
    Imports System.Runtime.InteropServices

    Public Class Page
        <Runtime.InteropServices.DllImport("winspool.Drv", EntryPoint:="OpenPrinterW", _
          SetLastError:=True, CharSet:=CharSet.Unicode, _
          ExactSpelling:=True, CallingConvention:=CallingConvention.StdCall)> _
       Public Shared Function OpenPrinter(ByVal src As String, ByRef hPrinter As IntPtr, ByVal pd As Long) As Boolean
        End Function

        <System.Runtime.InteropServices.DllImportAttribute("winspool.drv", SetLastError:=True)> _
        Public Shared Function ClosePrinter(ByVal phPrinter As IntPtr) As Integer
        End Function

        <DllImport("winspool.drv")> _
        Public Shared Function SetPrinter(ByVal hPrinter As IntPtr, ByVal level As Integer, ByVal lpBytes As IntPtr, ByVal command As Integer) As Boolean
        End Function

        Public Shared Function Setting(ByVal PageName As String) As Boolean
            Try
                Dim printerSettings As PrinterSettings
                Dim document As New PrintDocument()

                printerSettings = document.PrinterSettings

                Dim hPrinter As IntPtr
                OpenPrinter(printerSettings.PrinterName, hPrinter, 0)

                Dim p As PaperSize = Nothing
                Dim ps As PaperSize
                For Each ps In document.PrinterSettings.PaperSizes
                    If ps.PaperName.Equals(PageName) Then
                        p = ps
                    End If
                Next
                document.DefaultPageSettings.PaperSize = p

                Dim hDevMode As IntPtr = printerSettings.GetHdevmode(document.DefaultPageSettings)
                Dim ret As Boolean = SetPrinter(hPrinter, 9, hDevMode, 0)
                ClosePrinter(hPrinter)
                Return True
            Catch ex As Exception

            End Try

        End Function
    End Class

  • 相关阅读:
    Orcale分析函数OVER(PARTITION BY... ORDER BY...)的讲解
    Linux下安装Redmine(项目管理软件)
    CentOS5.4安装redmine详细步骤
    CentOS安装redmine 2后的简单配置
    在linux上安装redmine
    Linux安装MediaWiki
    Linux下安装配置MediaWiKi全过程
    用Navicat_SSH 连接数据库服务器
    基于C#的MongoDB数据库开发应用(4)--Redis的安装及使用
    基于C#的MongoDB数据库开发应用(3)--MongoDB数据库的C#开发之异步接口
  • 原文地址:https://www.cnblogs.com/lbnnbs/p/4784581.html
Copyright © 2020-2023  润新知