0

我有一份销售完成后需要打印的报告。

我在使用 PrintForm 和 PrintDocument 组件时遇到长度和打印问题,但是如果我右键单击并从列表中选择打印,则报告打印完美。

有什么方法可以在我的表单加载事件中编写代码来模仿右键打印?

多年来,我一直在为我的项目的这一部分苦苦挣扎,现在整个事情都落后于计划。

我的整个收据表单页面的代码是:

Imports System.Data.OleDb
Imports System.IO
Imports System.Drawing.Printing

Public Class Receipt
Public PicLocation As String
Dim Ctrl1, Ctrl2 As Control
Dim CN As New OleDb.OleDbConnection
Dim CMD As New OleDb.OleDbCommand
Dim DataR As OleDb.OleDbDataReader

'To display into datagrid purpose
Dim dataS As New DataSet
Dim dataAd As New OleDb.OleDbDataAdapter
Public SqlStr, SqlStr1, DBPath, DBStatus, SearchBox As String
Dim X, Y, SqlH, Onh As Integer
Dim SqlUser As String
Dim DataP As Decimal
Dim Balance As Integer

Private Sub Receipt_Load(sender As Object, e As EventArgs) Handles MyBase.Load

    'TODO: This line of code loads data into the 'ProductListDataSet' table.
    DBPath = (Application.StartupPath & "\ProductList.accdb")
    If CN.State = ConnectionState.Open Then
        CN.Close()
        DBStatus = ("Not Connected")
    End If
    SqlStr = ("Provider = Microsoft.ACE.OLEDB.12.0;Data Source =" & DBPath)
    CN.ConnectionString = SqlStr
    CN.Open()
    Onh = Nothing

    lblTime.Text = DateAndTime.Now
    lblUser.Text = Login.userTB.Text

    Dim sql As String
    sql = "SELECT * Receipt"
    Me.ReceiptTableAdapter.ClearBeforeFill = True
    Me.ReceiptTableAdapter.Connection = CN
    Me.ReceiptTableAdapter.Connection.CreateCommand.CommandText = sql
    Me.ReceiptTableAdapter.Fill(Me.ProductListDataSet.Receipt)
    Me.ReportViewer1.RefreshReport()
    Me.Refresh()


End Sub

Private Sub Button1_Click_1(sender As Object, e As EventArgs) Handles Button1.Click

    With Me.PrintForm1
        .PrintAction = Printing.PrintAction.PrintToPrinter

        Dim MyMargins As New Margins
        With MyMargins
            .Left = 0
            .Right = 0
            .Top = 0
            .Bottom = 0
        End With
        .PrinterSettings.DefaultPageSettings.Margins = MyMargins
        .Print(Me, PowerPacks.Printing.PrintForm.PrintOption.CompatibleModeClientAreaOnly)

    End With

End Sub

End Class
4

0 回答 0