VB.Net 2008打印DataGridView(文本换行顶部标题列和宽度锁定)

在VB.Net 2008应用程序中,作者面临的问题是如何在打印DataGridView时处理长列标题。他们需要在一页内打印所有10个字段,同时实现顶部标题列的文本换行和宽度锁定。目前的代码无法实现这个需求,作者寻求解决方案和示例代码。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

我正在使用VB.Net 2008应用程序。

我正在使用DataGridView。 我有一个打印选项,在这里我需要打印DataGridView。

我将此代码用于“打印”和“打印预览”。


    Dim MyDataGridViewPrinter As DataGridViewPrinter  
    Private Function SetupThePrinting() As Boolean
        Dim MyPrintDialog As PrintDialog = New PrintDialog() 
        MyPrintDialog.AllowCurrentPage = False
        MyPrintDialog.AllowPrintToFile = False
        MyPrintDialog.AllowSelection = False
        MyPrintDialog.AllowSomePages = True
        MyPrintDialog.PrintToFile = False
        MyPrintDialog.ShowHelp = False
        MyPrintDialog.ShowNetwork = False 
        PrintDocument1.PrinterSettings = MyPrintDialog.PrinterSettings
        PrintDocument1.DefaultPageSettings.Margins = New Margins(10, 10, 10, 10) 
               MyDataGridViewPrinter = New DataGridViewPrinter(DataGridView1, PrintDocument1, False, True, "Price Manager", New Font("Tahoma", 18, FontStyle.Bold, GraphicsUnit.Point), Color.Black, True) 
        Return True
    End Function 
    Private Sub PrintDocument1_PrintPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
        Dim more As Boolean 
        Try
            more = MyDataGridViewPrinter.DrawDataGridView(e.Graphics)
            If more Then e.HasMorePages = True
        Catch Ex As Exception
        End Try
    End Sub 
    ' The Print Preview Button
    Private Sub btnPrintPreview_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnPrintPreview.Click
        If SetupThePrinting() Then
            Dim MyPrintPreviewDialog As PrintPreviewDialog = New PrintPreviewDialog()
            MyPrintPreviewDialog.Document = PrintDocument1
            MyPrintPreviewDialog.ShowDialog()
        End If
    End Sub 
    ' The Print Button
    Private Sub btnPrint_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnPrint.Click
        If SetupThePrinting() Then PrintDocument1.Print()
    End Sub 
附加了我用于打印的课程。

我有10个字段显示在datagridview中。 由于最后5列的标题很长,因此datagridview不适合放在1页内(不在一个页面中显示所有10个字段)。 但是有没有办法我可以“文本换行”顶部标题列并锁定宽度,然后它应该完美地打印在一页上。

我搜索了很多,但找不到。

如果您知道如何“顶部文字”换行并锁定宽度以在一页上打印,请帮助我。 如果您可以提供示例,那将非常有帮助。

提前致谢。

附加的文件
档案类型:txt 打印Code.txt (22.1 KB,819次观看)

From: https://bytes.com/topic/visual-basic-net/insights/931236-vb-net-2008-print-datagridview-text-wrap-top-header-column-lock-width

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值