PrintPreviewControl和Form Design在另一个OS上的工作方式有所不同。 VB.NET

时间:2018-09-01 13:29:17

标签: windows vb.net printing print-preview form-designer

我正在编写用于小型酒店会计的应用程序,我正在使用Visual Studio 2013,且操作系统为Windows 10(笔记本电脑)。在完成应用程序的发布后,使用发布向导将其发布,然后一切顺利,直到我将发布的文件复制到另一台包含操作系统的计算机上:Windows 7 SP1,该应用程序成功运行,但是在表单设计和预览报告打印方面稍有更改。

这里有两张图片来说明到底是什么问题... enter image description here   enter image description here

如果有人可以解释发生了什么事情以及如何解决此问题,将受到尊重。

这是我的课程,其中包含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

0 个答案:

没有答案