日期:2014-05-18  浏览次数:20527 次

哪位朋友能提供一个datagrid打印的类或脚本,要vb.net的!
哪位朋友能提供一个datagrid打印的类或脚本,要vb.net的,谢谢!

------解决方案--------------------
可以把DataGrid输出至Word或是Excel之后,打印.
参考:
http://blog.csdn.net/insus/archive/2008/03/31/2231945.aspx
------解决方案--------------------
VB.NET code

 '以下为模块内部使用 
    Private ev As PrintPageEventArgs 
    Private PrintDocument1 As PrintDocument 
    Private DataGridColumn As DataColumn 
    Private DataGridRow As DataRow 
    Private DataTable1 As DataTable 
    Private Cols As Integer                             '当前要打印的列 
    Private Rows As Integer = 0                         '当前要打印的行 
    Private ColsCount As Integer                        '当前DATAGRID共有多少列 
    Private PrintingLineNumber As Integer = 0           '当前正要打印的行号 
    Private PageRecordNumber As Integer                 '当前要所要打印的记录行数,由计算得到. 
    Private PrintingPageNumber As Integer = 0           '正要打印的页号 
    Private PageNumber As Integer                       '共需要打印的页数 
    Private PrintRecordLeave As Integer                 '当前还有多少页没有打印 
    Private PrintRecordComplete As Integer = 0         '已经打印完的记录数 
    Private Pleft As Integer 
    Private Ptop As Integer 
    Private Pright As Integer 
    Private Pbottom As Integer 
    Private Pwidth As Integer 
    Private Pheigh As Integer 

    Private DrawBrush As New SolidBrush(System.Drawing.Color.Black)     '当前画笔颜色 
    Private PrintRecordNumber As Integer '每页打印的记录条数 
    Private Totalpage As Integer '总共应该打印的页数 

    Sub New(ByVal TableSource As DataTable) 
        DataTable1 = New DataTable 
        DataTable1 = TableSource 
        ColsCount = DataTable1.Columns.Count 
    End Sub 

    '用户自定义字体及字号 
    Public WriteOnly Property SetTableFont() As System.Drawing.Font 
        Set(ByVal Value As System.Drawing.Font) 
            TableFont = Value 
        End Set 
    End Property 
    Public WriteOnly Property SetHeadFont() As System.Drawing.Font 
        Set(ByVal Value As System.Drawing.Font) 
            HeadFont = Value 
        End Set 
    End Property 
    Public WriteOnly Property SetSubHeadFont() As System.Drawing.Font 
        Set(ByVal Value As System.Drawing.Font) 
            SubHeadFont = Value 
        End Set 
    End Property 
    Public WriteOnly Property SetFootFont() As System.Drawing.Font 
        Set(ByVal Value As System.Drawing.Font) 
            FootFont = Value 
        End Set 
    End Property 
    Public WriteOnly Property SetSubFootFont() As System.Drawing.Font 
        Set(ByVal Value As System.Drawing.Font) 
            SubFootFont = Value 
        End Set 
    End Property 
    Public WriteOnly Property SetHeadText() As String 
        Set(ByVal Value As String) 
            HeadText = Value 
        End Set 
    End Property 
    Public WriteOnly Property SetSubHeadLeftText() As String 
        Set(ByVal Value As String) 
            SubHeadLeftText = Value 
        End Set 
    End Property 
    Public WriteOnly Property SetSubHeadRightText() As String 
        Set(ByVal Value As String) 
            SubHeadRightText = Value 
        End Set 
    End Property 
    Public WriteOnly Property SetFootText() As String 
        Set(ByVal Value As String) 
            FootText = Value 
        End Set 
    End Property 
    Public WriteOnly Property SetSubFootLeftText() As String 
        Set(ByVal Value As String) 
            SubFootLeftText = Value 
        End Set 
    End Property 
    Public WriteOnly Property SetSubFootRightText() As String 
        Set(ByVal Value As String) 
            SubfootRightText = Value 
        End Set 
    End Property 
    Public WriteOnly Property SetHeadHeight() As Integer 
        Set(ByVal Value As Integer) 
            HeadHeight = Value 
        End Set 
    End Property 
    Public WriteOnly Property SetSubHeadHeight() As Integer 
        Set(ByVal Value As Integer) 
            SubHeadHeight = Value 
        End Set 
    End Prope