vb.net 如何在vb.net中将papersize设置为legal
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16168771/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 13:22:08 来源:igfitidea点击:
How to set papersize to legal in vb.net
提问by Rara Arar
Im trying to print the contents of my datagridview to a legal or long size bond paper but i can't find the code to make the paper in preview dialog to long. Here is my code for print preview and print:
我试图将我的 datagridview 的内容打印到合法或长尺寸的证券纸上,但我找不到使预览对话框中的纸张变长的代码。这是我的打印预览和打印代码:
Private Sub btnPreview_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPreview.Click
Dim strcon As New OleDbConnection("Provider=Microsoft.Jet.Oledb.4.0;Data Source=C:\Users\user\Documents\Visual Studio 2008\Projects\NMGInventory\NMGInventory\Supplies.mdb")
Try
strcon.Open()
Dim sql As String
sql = "SELECT * From [product info]"
Dim adapter As New OleDbDataAdapter(sql, strcon)
Dim dt As New DataTable("product info")
adapter.Fill(dt)
print.DefaultPageSettings.Landscape = True
.
preview.PrintPreviewControl.Zoom = 1
preview.Document = print
preview.Show()
AddHandler print.PrintPage, AddressOf print_PrintPage
strcon.Close()
Catch Ex As Exception
MessageBox.Show(Ex.Message)
End Try
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
Dim CellRightPos As Integer = print.PrinterSettings.DefaultPageSettings.Margins.Right
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 CellWidth1 = DataGridView1.Rows(3).Cells(Cell).Size.Width + -30
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
回答by Sathish
Set the following setting
设置以下设置
Dim xCustomSize As New PaperSize("Legal", 850, 1400)
Me.DefaultPageSettings.PaperSize = xCustomSize

