VB.net:打印 RTL DGV 内容

问题描述

下面的代码打印一个 DGV 从 LTR 中选择列。 我已经用过: fmt.FormatFlags = fmt.FormatFlags 或 StringFormatFlags.DirectionRightToLeft 它在单元格 RTL 内确定了方向,但我需要的是制作整个 DGV RTL。 任何帮助,将不胜感激。 谢谢 ………………………………………………………………………………………………………………………………………………………… ………………………………………………………………………………………………………………………………………………………… ………………………………………………………………………………………………………………………………………………………… ………………………………………………………………………………………………………………………………………………………… ………………………………………………………………………………………………………………………………………………………… ………………………………………………………………………………………………………………………………………………………… …………………………………………………………………………………………………………………………………………………………

Private mRow As Integer = 0
Private newpage As Boolean = True
Private Sub PrintDocument1_PrintPage(sender As System.Object,e As PrintPageEventArgs) Handles PrintDocument1.PrintPage

    Dim fmt As StringFormat = New StringFormat(StringFormatFlags.LineLimit)
    fmt.FormatFlags = fmt.FormatFlags Or StringFormatFlags.DirectionRightToLeft
    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
    If newpage Then
        row = DGV.Rows(mRow)
        x = e.MarginBounds.Left
        For Each cell As DataGridViewCell In row.Cells
            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)
                Select Case DGV.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(DGV.Columns(cell.ColumnIndex).HeaderText,DGV.Font,Brushes.Black,rc,fmt)
                x += rc.Width
                h = Math.Max(h,rc.Height)
            End If
        Next
        y += h
    End If
    newpage = False
    Dim thisNDX As Int32
    For thisNDX = mRow To DGV.RowCount - 1
        If DGV.Rows(thisNDX).IsNewRow Then Exit For
        row = DGV.Rows(thisNDX)
        x = e.MarginBounds.Left
        h = 0
        x = e.MarginBounds.Left
        For Each cell As DataGridViewCell In row.Cells
            If cell.Visible Then
                rc = New Rectangle(x,cell.Size.Height)
                e.Graphics.DrawRectangle(Pens.Black,0)
                End Select

                e.Graphics.DrawString(cell.FormattedValue.ToString(),rc.Height)
            End If
        Next
        y += h
        mRow = thisNDX + 1
        If y + h > e.MarginBounds.Bottom Then
            e.HasMorePages = True
            newpage = True
            Return
        End If
    Next

End Sub

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)