我已经设法打印我的数据网格视图的内容,但它不适合纵向模式。我想在横向模式下打印它会。
我有我的数据集的代码来填充datagridview。
Private Sub print_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim query As String = "SELECT * FROM TBLusers"
Dim DA As New SqlDataAdapter(query, CN)
Dim DS As New DataSet
CN.Open()
DA.Fill(DS, "Users")
CN.Close()
DataGridView1.DataSource = DS.Tables("Users")
'DataGridView1.DataMember = "Users"
End Sub
这是我猜的打印功能?我是从教程中得到的。
Private Sub printDocument1_PrintPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
Dim dataGridViewImage As New Bitmap(Me.DataGridView1.Width, Me.DataGridView1.Height)
DataGridView1.DrawToBitmap(dataGridViewImage, New Rectangle(0, 0, Me.DataGridView1.Width, Me.DataGridView1.Height))
e.Graphics.DrawImage(dataGridViewImage, 0, 0)
End Sub
这是打印预览。
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
PrintPreviewDialog2.Document = PrintDocument1
PrintPreviewDialog2.PrintPreviewControl.Zoom = 1
PrintPreviewDialog2.ShowDialog()
End Sub
和打印...
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
PrintDocument1.Print()
End Sub
我试过了 PrintDocument1.PrinterSettings.DefaultPageSettings.Landscape = True
但它似乎没有用?
答案 0 :(得分:6)
您正在为打印机设置DefaultPage
设置。
尝试为文档本身设置它:
PrintDocument1.DefaultPageSettings.Landscape = True
PrintDocument1.Print()