gpt4 book ai didi

vb.net - 以横向格式打印和预览 DataGridView

转载 作者:行者123 更新时间:2023-12-04 15:00:34 26 4
gpt4 key购买 nike

 Private Sub btnPreview_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPreview.Click
preview.PrintPreviewControl.Zoom = 1
preview.Document = print
print.PrinterSettings.DefaultPageSettings.Landscape = True
preview.Show()

AddHandler print.PrintPage, AddressOf print_PrintPage

End Sub

Protected Sub print_PrintPage(ByVal sender As Object, ByVal e As PrintPageEventArgs)
Dim ColumnCount As Integer = DataGridView1.ColumnCount
Dim RowCount As Integer = DataGridView1.RowCount

Dim CellTopPos As Integer = print.PrinterSettings.DefaultPageSettings.Margins.Top

For Row = 0 To RowCount - 1

Dim CellLeftPos As Integer = print.PrinterSettings.DefaultPageSettings.Margins.Left

For Cell = 0 To ColumnCount - 1

Dim CellValue As String = DataGridView1.Rows(Row).Cells(Cell).Value.ToString()
Dim CellWidth = DataGridView1.Rows(Row).Cells(Cell).Size.Width + 50
Dim CellHeight = DataGridView1.Rows(Row).Cells(Cell).Size.Height

Dim Brush As New SolidBrush(Color.Black)
e.Graphics.DrawString(CellValue, New Font("Century Gothic", 10), Brush, CellLeftPos, CellTopPos)
e.Graphics.DrawRectangle(Pens.Black, CellLeftPos, CellTopPos, CellWidth, CellHeight)

CellLeftPos += CellWidth
Next

CellTopPos += DataGridView1.Rows(Row).Cells(0).Size.Height
Next

End Sub

这是我用于预览和打印 datagridview 内容的代码。我尝试使用 DefaultPageSettings 代码,但它不起作用。我也试图以居中的格式打印它

最佳答案

尝试设置 PrintDocument 的 DefaultPageSettings 属性,而不是 PrinterSettings:

'PrintDocument1.PrinterSettings.DefaultPageSettings.Landscape = True
PrintDocument1.DefaultPageSettings.Landscape = True

关于vb.net - 以横向格式打印和预览 DataGridView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15786955/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com