添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
相关文章推荐
买醉的牛肉面  ·  Amazon.com: Cell ...·  1 月前    · 
有胆有识的砖头  ·  ICLR 2023 ...·  1 年前    · 
坚强的鸵鸟  ·  C# ...·  1 年前    · 
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

im writing an app for accountings of small hotel, i'm working with Visual Studio 2013, on OS: windows 10 (Laptop). After finishing the app just published it using publish wizard, then everything was going great till i copied the published files to another computer contains OS: Windows 7 SP1, the app worked successfully but with a little changes in form design and while preview reports printing.

Here's two pictures to explain what is exactly the problem...

If anyone could explain what's going on and what to do to solve this issue would be respected.

Here's my class which contains printpreviewcontrol code:

Private mRow As Integer = 0
Private newpage As Boolean = True
Private Sub PrintDocument1_PrintPage(sender As Object, e As PrintPageEventArgs) Handles PrintDocument1.PrintPage
        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
            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
            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
    Catch ex As Exception
        MsgBox(ex.ToString, MsgBoxStyle.Critical)
    End Try
                Maybe there's something wrong in your code but how would we know, given that you haven't shown us that code? Please read this and this.
– jmcilhinney
                Sep 1, 2018 at 14:06
                Too much code without some indication of where the issue is.  Did you follow the second link I provided?  You should have followed both.
– jmcilhinney
                Sep 1, 2018 at 14:26
                @jmcilhinney mate, i have no errors in my code, i'm just in need of explaination to the behavior of the form design or the PrintPreviewControl, i need to know why my locations of the rectangles of drawstrings are changed from computer to another, also the form design why it get smaller button on another computer, i shouldnt have attached code, but might help.
– Ramy Khaled
                Sep 1, 2018 at 14:39
                If you're not interested in providing a minimal, complete and verifiable example of the issue then I'm not interested in trying to work out what the issue might be.  You'll likely find that most others aren't either.
– jmcilhinney
                Sep 1, 2018 at 15:02
        

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.