纸张设置175MM*900MM
平推针式打印机,打完还是要进纸,
然后纸在里面不动了,需要重启打印机才能恢复
请问如何解决?
我感觉是红色字体那段出错了,但是不知道这段是什么意思,从MSDN上抄的。Public Sub PrintTest()
    Dim StrWidth As Single
    If Combo1.Text = "" Then
      MsgBox "请选择币种!"
      Exit Sub
    End If
    Printer.Font.Name = 宋体
    Printer.FontSize = 12
    Printer.CurrentX = 75
    Printer.CurrentY = 8
    Printer.Print Text(0).Text
    StrWidth = Printer.TextWidth(Text(1).Text)
    Printer.CurrentX = 70 - StrWidth
    Printer.CurrentY = 15
    Printer.Print Text(1).Text
    StrWidth = Printer.TextWidth(Text(5).Text)
    Printer.CurrentX = 145 - StrWidth
    Printer.CurrentY = 15
    Printer.Print Text(5).Text
    StrWidth = Printer.TextWidth(Text(2).Text)
    Printer.CurrentX = 70 - StrWidth
    Printer.CurrentY = 25
    Printer.Print Text(2).Text
    StrWidth = Printer.TextWidth(Text(6).Text)
    Printer.CurrentX = 145 - StrWidth
    Printer.CurrentY = 25
    Printer.Print Text(6).Text
    StrWidth = Printer.TextWidth(Text(3).Text)
    Printer.CurrentX = 50 - StrWidth
    Printer.CurrentY = 33
    Printer.Print Text(3).Text
    Printer.CurrentX = 65
    Printer.CurrentY = 33
    Printer.Print Text(4).Text
    Printer.CurrentX = 105
    Printer.CurrentY = 33
    Printer.Print Text(7).Text
    StrWidth = Printer.TextWidth(Text(8).Text)
    Printer.CurrentX = 145 - StrWidth
    Printer.CurrentY = 33
    Printer.Print Text(8).Text
    StrWidth = Printer.TextWidth(Text(9).Text)
    Printer.CurrentX = 145 - StrWidth
    Printer.CurrentY = 45
    Printer.Print Text(9).Text
    Printer.CurrentX = 80
    Printer.CurrentY = 45
    Printer.Print Label2.Caption
    Printer.CurrentX = 15
    Printer.CurrentY = 45
    Printer.Print Label12.Caption
    Printer.CurrentX = 25
    Printer.CurrentY = 75
    Printer.Print Text(10).Text
    Printer.EndDoc
    MsgBox "打印完毕"
End SubPrivate Sub form_Load()
  Dim NumForms As Long, I As Long
  Dim FI1 As FORM_INFO_1
  Dim aFI1() As FORM_INFO_1           ' Working FI1 array
  Dim Temp() As Byte                  ' Temp FI1 array
  Dim BytesNeeded As Long
  Dim PrinterName As String           ' Current printer
  Dim PrinterHandle As Long           ' Handle to printer
  Dim FormItem As String              ' For ListBox
  Dim RetVal As Long
  Dim FormSize As SIZEL               ' Size of desired form  PrinterName = Printer.DeviceName    ' Current printer
  If OpenPrinter(PrinterName, PrinterHandle, 0&) Then
    With FormSize   ' Desired page size
        .cx = 175000
        .cy = 90000
    End With
    ReDim aFI1(1)
    RetVal = EnumForms(PrinterHandle, 1, aFI1(0), 0&, BytesNeeded, _
             NumForms)
    ReDim Temp(BytesNeeded)
    ReDim aFI1(BytesNeeded / Len(FI1))
    RetVal = EnumForms(PrinterHandle, 1, Temp(0), BytesNeeded, _
             BytesNeeded, NumForms)
    Call CopyMemory(aFI1(0), Temp(0), BytesNeeded)
    For I = 0 To NumForms - 1
        With aFI1(I)
            ' List name and size including the count (index).
            FormItem = PtrCtoVbString(.pName) & " - " & .Size.cx / 1000 & _
               " mm X " & .Size.cy / 1000 & " mm   (" & I + 1 & ")"

            List1.AddItem FormItem
        End With
    Next I
    ClosePrinter (PrinterHandle)
  End If
End Sub

解决方案 »

  1.   

                FormItem = PtrCtoVbString(.pName) & " - " & .Size.cx / 1000 & _
                   " mm X " & .Size.cy / 1000 & " mm   (" & I + 1 & ")"

    这段在代码里没法显示红色呀~~~
      

  2.   

    应该不是红色部分问题.
    调试查看一下 aFI1(I) 的数量,是否含有空页
      

  3.   

    谢谢,因为这部分是MSDN上抄来的,还没搞懂这个aFI1的意思
    请教这个应该如何查看?
      

  4.   

    运行到
        For I = 0 To NumForms - 1
            With aFI1(I)这段时,aFI1()的cx值是215900,cy值是279400
      

  5.   

    设置的纸张大小是175MM*90MM
    如果我放A4纸进去,打完直接卡在里面不退出来了
    如果放大小正好的纸张,打完退出来,要求再放纸……
      

  6.   

    设置纸张的代码
    Public Function SelectForm(FormName As String, ByVal MyhWnd As Long) _
        As Integer
    Dim nSize As Long           ' Size of DEVMODE
    Dim pDevMode As DEVMODE
    Dim PrinterHandle As Long   ' Handle to printer
    Dim hPrtDC As Long          ' Handle to Printer DC
    Dim PrinterName As String
    Dim aDevMode() As Byte      ' Working DEVMODE
    Dim FormSize As SIZELPrinterName = Printer.DeviceName  ' Current printer
    hPrtDC = Printer.hdc              ' hDC for current Printer
    SelectForm = FORM_NOT_SELECTED    ' Set for failure unless reset in code.' Get a handle to the printer.
    If OpenPrinter(PrinterName, PrinterHandle, 0&) Then
        ' Retrieve the size of the DEVMODE.
        nSize = DocumentProperties(MyhWnd, PrinterHandle, PrinterName, 0&, _
                0&, 0&)
        ' Reserve memory for the actual size of the DEVMODE.
        ReDim aDevMode(1 To nSize)    ' Fill the DEVMODE from the printer.
        nSize = DocumentProperties(MyhWnd, PrinterHandle, PrinterName, _
                aDevMode(1), 0&, DM_OUT_BUFFER)
        ' Copy the Public (predefined) portion of the DEVMODE.
        Call CopyMemory(pDevMode, aDevMode(1), Len(pDevMode))
        
        ' If FormName is "MyCustomForm", we must make sure it exists
        ' before using it. Otherwise, it came from our EnumForms list,
        ' and we do not need to check first. Note that we could have
        ' passed in a Flag instead of checking for a literal name.
        If FormName = "MyCustomForm" Then
            ' Use form "MyCustomForm", adding it if necessary.
            ' Set the desired size of the form needed.
            With FormSize   ' Given in thousandths of millimeters
                .cx = 175000   ' width
                .cy = 95000   ' height
            End With
            If GetFormName(PrinterHandle, FormSize, FormName) = 0 Then
                ' Form not found - Either of the next 2 lines will work.
                'FormName = AddNewForm(PrinterHandle, FormSize, "MyCustomForm")
                AddNewForm PrinterHandle, FormSize, "MyCustomForm"
                If GetFormName(PrinterHandle, FormSize, FormName) = 0 Then
                    ClosePrinter (PrinterHandle)
                    SelectForm = FORM_NOT_SELECTED   ' Selection Failed!
                    Exit Function
                Else
                    SelectForm = FORM_ADDED  ' Form Added, Selection succeeded!
                End If
            End If
        End If
        
        ' Change the appropriate member in the DevMode.
        ' In this case, you want to change the form name.
        pDevMode.dmFormName = FormName & Chr(0)  ' Must be NULL terminated!
        ' Set the dmFields bit flag to indicate what you are changing.
        pDevMode.dmFields = DM_FORMNAME    ' Copy your changes back, then update DEVMODE.
        Call CopyMemory(aDevMode(1), pDevMode, Len(pDevMode))
        nSize = DocumentProperties(MyhWnd, PrinterHandle, PrinterName, _
                aDevMode(1), aDevMode(1), DM_IN_BUFFER Or DM_OUT_BUFFER)    nSize = ResetDC(hPrtDC, aDevMode(1))   ' Reset the DEVMODE for the DC.    ' Close the handle when you are finished with it.
        ClosePrinter (PrinterHandle)
        ' Selection Succeeded! But was Form Added?
        If SelectForm <> FORM_ADDED Then SelectForm = FORM_SELECTED
    Else
        SelectForm = FORM_NOT_SELECTED   ' Selection Failed!
    End If
    End Function
      

  7.   

    应该通过 Printer.PageSize 来设置纸张。
    Printer 对象的打印机属性有的象“快照”,你通过 API 修改的设置,Printer 对象很可能没有得到通知,所以不重新获取打印机属性,还是用原先的纸张设置在进行打印输出。
      

  8.   

    2000和NT以上系统不能用pagesize方法,只能用API……
    朋友再帮忙看看用API应该怎么改吧,谢谢!
      

  9.   

    http://support.microsoft.com/kb/q282474/
    源码是这里来的,最后它打印也是通过print打印的,API如何打印?
    而且我不需要打整个FORM,只打其中的text.text
      

  10.   

    我把API去掉,直接用printer打印
    打印机设置默认自定义175*95的纸张
    还是出现卡死打印机
    看来不是API的问题了。