我一直有很多问题让打印对话框和页面设置一起工作,从文本框中打印文本,我花了几个小时做研究和尝试一切,我无法让它工作,有人可以请帮助我,并给我代码从文本框打印文档,并设置页面以使用它(就像在记事本中一样)
这是我的代码不能正常工作
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
If (PrintDialog1.ShowDialog() = DialogResult.OK) Then
PrintDocument1.Print()
End If
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
PageSetupDialog1.ShowDialog()
PrintDocument1.DefaultPageSettings = PageSetupDialog1.PageSettings
End Sub
Private Sub PrintDocument1_PrintPage(sender As Object, e As Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
Dim textArea As New Rectangle()
e.Graphics.DrawString(TextBox1.Text, TextBox1.Font, Brushes.Black, 100, 100)
End Sub
由于
答案 0 :(得分:0)
如果您使用PrintDocument
,则可以将文字绘制到Rectangle
,它会自然换行。您还可以使用StringFormat对象进行其他格式化帮助。
Private Sub printDoc_PrintPage(ByVal sender As Object, ByVal ev As PrintPageEventArgs) Handles printDoc.PrintPage
Dim textArea As New Rectangle(e.MarginBounds.Left, e.MarginBounds.Top, e.MarginBounds.Width, e.MarginBounds.Height)
e.Graphics.DrawString(textbox1.Text, New Font("Consolas", 10), Brushes.Navy, textArea)
'other stuff
End Sub