4
我已經設法打印我的datagrid視圖的內容,但它不適合縱向模式。我想在橫向模式下打印它會做。在橫向模式下打印vb.net
我有這個代碼爲我的數據集來填充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 =真
,但它似乎犯規的工作?
謝謝!有效! –
傻我。我在做同樣的錯誤!感謝羅賓! –