2011-08-10 38 views
0

vb.netの行ごとに生のテキストを1行に渡すことでテキストを1行ずつ印刷したいと考えています。 C言語でのprintfのような可能性のあるドットマトリックスプリンタを使用してVb.netから生のテキストを印刷

何かが

+0

:CTポート次のように制御文字などを含むプリンタに送信するデータとこんにちはを交換し、それを呼び出して任意のドライバーを使用して(私は一般的にドライバーのみ汎用/テキストを使用)し、これはhttp://blogs.lessthandot.com/index.php/DesktopDev/MSTech/VBNET/printing-to-a-zebra-printer-from-vb-net – Jodrell

+0

プリンタはローカルですか、ネットワークですか? – Jodrell

+0

これもhttp://www.taylorsnet.co.uk/SourceCodeDetail.aspx?SourceID=34 – Jodrell

答えて

-1

回答を提供するために、私の意図ではなく、ということです補足答弁など -

され、次の(管理対象外)VB6のコードありませんあなたは何をしたいのですが、簡単に変換することができます.NETフレンドリー:

 Public Type DOCINFO 
      pDocName As String 
      pOutputFile As String 
      pDatatype As String 
     End Type 

Declare Function ClosePrinter Lib "winspool.drv" (ByVal hPrinter As Long) As Long 
Declare Function EndDocPrinter Lib "winspool.drv" (ByVal hPrinter As Long) As Long 
Declare Function EndPagePrinter Lib "winspool.drv" (ByVal hPrinter As Long) As Long 
Declare Function OpenPrinter Lib "winspool.drv" Alias "OpenPrinterA" (ByVal pPrinterName As String, phPrinter As Long, ByVal pDefault As Long) As Long 
Declare Function StartDocPrinter Lib "winspool.drv" Alias "StartDocPrinterA" (ByVal hPrinter As Long, ByVal Level As Long, pDocInfo As DOCINFO) As Long 
Declare Function StartPagePrinter Lib "winspool.drv" (ByVal hPrinter As Long) As Long 
Declare Function WritePrinter Lib "winspool.drv" (ByVal hPrinter As Long, pBuf As Any, ByVal cdBuf As Long, pcWritten As Long) As Long 

Public Function PrintRawData(ByVal sPrinter As String, ByVal sDocName As String, ByVal sData As String) As Boolean 
On Error GoTo PrintErr: 

      Dim lhPrinter As Long, lReturn As Long, lpcWritten As Long 
      Dim lDoc As Long, sWrittenData As String 
      Dim MyDocInfo As DOCINFO 
      Dim pOutput As Printer 
      Dim p As Printer 

      For Each p In Printers 
       If p.DeviceName = sPrinter Then 
        Set pOutput = p 
        GoTo StartPrinting 
       End If 
      Next p 

      MsgBox "Unable to find the specified printer [" & sPrinter & _ 
      "] in the list of currently installed printers" & vbCrLf & _ 
      "Printing will be aborted", vbCritical 
      Exit Function 

StartPrinting: 
      lReturn = OpenPrinter(pOutput.DeviceName, lhPrinter, 0) 

      If lReturn = 0 Then 
       MsgBox "Print was unsuccessful. Make sure there is a printer installed on the port you are trying to print to" 
       Exit Function 
      End If 

      MyDocInfo.pDocName = sDocName 
      MyDocInfo.pOutputFile = vbNullString 
      MyDocInfo.pDatatype = vbNullString 
      lDoc = StartDocPrinter(lhPrinter, 1, MyDocInfo) 
      Call StartPagePrinter(lhPrinter) 

      sWrittenData = sData 

      lReturn = WritePrinter(lhPrinter, ByVal sWrittenData, Len(sWrittenData), lpcWritten) 
      lReturn = EndPagePrinter(lhPrinter) 'need this?? 
      lReturn = EndDocPrinter(lhPrinter) 
      lReturn = ClosePrinter(lhPrinter) 

      Exit Function 

PrintErr: 
    MsgBox "Print was unsuccessful. Make sure there is a printer installed on the port you are trying to print to" 
    Exit Function 

End Function 

これを使用するには、それを使用するプリンタをインストールする必要がありますあなたが見てきました

PrintRawData "Generic/Text Only", "My Document", "Hello" 
関連する問題