0

我正在编写一个用于小型酒店会计的应用程序,我正在使用 Visual Studio 2013,操作系统:Windows 10(笔记本电脑)。完成应用程序后,刚刚使用发布向导发布了它,然后一切都很好,直到我将发布的文件复制到另一台包含操作系统:Windows 7 SP1 的计算机上,该应用程序运行成功,但表单设计和预览报告打印时略有变化。

这里有两张图片来解释究竟是什么问题...... 在此处输入图像描述 在此处输入图像描述

如果有人能解释发生了什么以及如何解决这个问题,将受到尊重。

这是我的类,其中包含 printpreviewcontrol 代码:

Private mRow As Integer = 0
Private newpage As Boolean = True
Private Sub PrintDocument1_PrintPage(sender As Object, e As PrintPageEventArgs) Handles PrintDocument1.PrintPage
    Try
        Dim font36 = New Font("Playball", 36, FontStyle.Regular)
        Dim font8 = New Font("Lora", 8, FontStyle.Regular)
        Dim font20 = New Font("Lora", 20, FontStyle.Underline)
        Dim font16 = New Font("Lora", 16, FontStyle.Regular)
        e.Graphics.DrawString("Riviera Beach Chalets", font36, Brushes.Black, New Rectangle(150, 25, 800, 100))
        e.Graphics.DrawString("Accounting Reports", font20, Brushes.Black, New Rectangle(650, 45, 300, 50))

        e.Graphics.FillRectangle(Brushes.MistyRose, New Rectangle(101, 741, 19, 19))
        e.Graphics.DrawString("Accommondation Revenue or Beach Revenue or CoffeeShop Revenue is 0", font8, Brushes.Black, New Rectangle(125, 745, 500, 30))
        e.Graphics.DrawString("Amount Received Total :", font16, Brushes.Black, New Rectangle(570, 735, 500, 50))
        e.Graphics.DrawString(Report_Database.reporttot, font16, Brushes.Black, New Rectangle(850, 735, 500, 50))


        ' sets it to show '...' for long text
        Dim fmt As StringFormat = New StringFormat(StringFormatFlags.LineLimit)
        fmt.LineAlignment = StringAlignment.Center
        fmt.Trimming = StringTrimming.EllipsisCharacter
        Dim y As Int32 = e.MarginBounds.Top
        Dim rc As Rectangle
        Dim x As Int32
        Dim h As Int32 = 0
        Dim row As DataGridViewRow

        ' print the header text for a new page
        '   use a grey bg just like the control
        If newpage Then
            row = Report_Database.DataGridView1.Rows(mRow)

            x = 50
            For Each cell As DataGridViewCell In row.Cells
                ' since we are printing the control's view,
                ' skip invidible columns
                If cell.Visible Then
                    rc = New Rectangle(x, y, cell.Size.Width, cell.Size.Height)

                    e.Graphics.FillRectangle(Brushes.LightGray, rc)
                    e.Graphics.DrawRectangle(Pens.Black, rc)

                    ' reused in the data pront - should be a function
                    Select Case Report_Database.DataGridView1.Columns(cell.ColumnIndex).DefaultCellStyle.Alignment
                        Case DataGridViewContentAlignment.BottomRight,
                             DataGridViewContentAlignment.MiddleRight
                            fmt.Alignment = StringAlignment.Far
                            rc.Offset(-1, 0)
                        Case DataGridViewContentAlignment.BottomCenter,
                            DataGridViewContentAlignment.MiddleCenter
                            fmt.Alignment = StringAlignment.Center
                        Case Else
                            fmt.Alignment = StringAlignment.Near
                            rc.Offset(2, 0)
                    End Select

                    e.Graphics.DrawString(Report_Database.DataGridView1.Columns(cell.ColumnIndex).HeaderText,
                                                Report_Database.DataGridView1.Font, Brushes.Black, rc, fmt)
                    x += rc.Width
                    h = Math.Max(h, rc.Height)
                End If
            Next
            y += h

        End If
        newpage = False

        ' now print the data for each row
        Dim thisNDX As Int32
        For thisNDX = mRow To Report_Database.DataGridView1.RowCount - 1
            ' no need to try to print the new row
            If Report_Database.DataGridView1.Rows(thisNDX).IsNewRow Then Exit For

            row = Report_Database.DataGridView1.Rows(thisNDX)

            h = 0

            ' reset X for data
            x = 50

            ' print the data
            For Each cell As DataGridViewCell In row.Cells
                If cell.Visible Then
                    rc = New Rectangle(x, y, cell.Size.Width, cell.Size.Height)

                    ' SAMPLE CODE: How To 
                    ' up a RowPrePaint rule
                    If Val(row.Cells(2).Value) = 0 Or Val(row.Cells(3).Value) = 0 Or Val(row.Cells(4).Value) = 0 Then
                        Using br As New SolidBrush(Color.MistyRose)
                            e.Graphics.FillRectangle(br, rc)
                        End Using

                    End If

                    e.Graphics.DrawRectangle(Pens.Black, rc)

                    Select Case Report_Database.DataGridView1.Columns(cell.ColumnIndex).DefaultCellStyle.Alignment
                        Case DataGridViewContentAlignment.BottomRight,
                             DataGridViewContentAlignment.MiddleRight
                            fmt.Alignment = StringAlignment.Far
                            rc.Offset(-1, 0)
                        Case DataGridViewContentAlignment.BottomCenter,
                            DataGridViewContentAlignment.MiddleCenter
                            fmt.Alignment = StringAlignment.Center
                        Case Else
                            fmt.Alignment = StringAlignment.Near
                            rc.Offset(2, 0)
                    End Select

                    e.Graphics.DrawString(cell.FormattedValue.ToString(),
                                          Report_Database.DataGridView1.Font, Brushes.Black, rc, fmt)

                    x += rc.Width
                    h = Math.Max(h, rc.Height)
                End If

            Next
            y += h
            ' next row to print
            mRow = thisNDX + 1

            If y + h > e.MarginBounds.Bottom Then
                e.HasMorePages = True
                ' mRow -= 1   causes last row to rePrint on next page
                newpage = True
                Button1.Enabled = True
                Button4.Enabled = True
                If mRow = Report_Database.DataGridView1.RowCount Then
                    e.HasMorePages = False
                    Exit Sub
                End If
                Return
            End If
        Next
    Catch ex As Exception
        MsgBox(ex.ToString, MsgBoxStyle.Critical)
    End Try
4

0 回答 0