vsprinter中的Richtextbox打印 [英] Richtextbox Printing in vsprinter
本文介绍了vsprinter中的Richtextbox打印的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果我们在Richtextbox中输入一些内容,然后输入由"Tab"和":".如果:"之前的物质中的单词增加,则它会在Richtextbox中正确显示物质,但不能使用VB.net在Vsprinter中按原样打印.请尽快给我答案.
If we give some matter in Richtextbox and We type the word continuously seperated by "Tab" & ":".If words in matter before ":" increases then it shows matter in richtextbox properly but not print as it is in Vsprinter using VB.net .Please give me the answer as soon as possible.
In Richtextbox
AAA : bbbbb
AAAAA : bbbbbb
In VsPrinter Print Shows Result
AAA : bbbbb
AAAAA : bbbbbb
推荐答案
以下是使用VB.NET打印RichTextBox的代码.
Here is the code to print RichTextBox using VB.NET
Imports System
Imports System.Drawing
Imports System.Collections
Imports System.ComponentModel
Imports System.Windows.Forms
Imports System.Data
Imports System.IO
Public Class frmprinRichtext
Private myReader As StringReader
Private Sub PrinterSettingsFile_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PrinterSettingsFile.Click
Me.printDialog1.Document = Me.ThePrintDocument
printDialog1.ShowDialog()
End Sub
Private Sub PrintFile_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PrintFile.Click
printDialog1.Document = ThePrintDocument
Dim strText As String = Me.richTextBox1.Text
myReader = New StringReader(strText)
If printDialog1.ShowDialog() = DialogResult.OK Then
Me.ThePrintDocument.Print()
End If
End Sub
Private Sub PreviewFile_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PreviewFile.Click
Try
Dim strText As String = Me.richTextBox1.Text
myReader = New StringReader(strText)
Dim printPreviewDialog1 As New PrintPreviewDialog()
printPreviewDialog1.Document = Me.ThePrintDocument
printPreviewDialog1.FormBorderStyle = FormBorderStyle.Fixed3D
printPreviewDialog1.ShowDialog()
Catch exp As Exception
End Try
End Sub
Protected Sub ThePrintDocument_PrintPage(ByVal sender As Object, ByVal ev As System.Drawing.Printing.PrintPageEventArgs) Handles ThePrintDocument.PrintPage
Dim linesPerPage As Single = 0
Dim yPosition As Single = 0
Dim count As Integer = 0
Dim leftMargin As Single = ev.MarginBounds.Left
Dim topMargin As Single = ev.MarginBounds.Top
Dim line As String = Nothing
Dim printFont As Font = Me.richTextBox1.Font
Dim myBrush As New SolidBrush(Color.Black)
' Work out the number of lines per page, using the MarginBounds.
linesPerPage = ev.MarginBounds.Height / printFont.GetHeight(ev.Graphics)
' Iterate over the string using the StringReader, printing each line.
line = myReader.ReadLine()
While count < linesPerPage And (Nothing <> line)
' calculate the next line position based on
' the height of the font according to the printing device
yPosition = (topMargin + (count * printFont.GetHeight(ev.Graphics)))
' draw the next line in the rich edit control
ev.Graphics.DrawString(line, printFont, myBrush, leftMargin, yPosition, New StringFormat())
count += 1
line = myReader.ReadLine()
End While
' If there are more lines, print another page.
If Not (line Is Nothing) Then
ev.HasMorePages = True
Else
ev.HasMorePages = False
End If
myBrush.Dispose()
End Sub 'ThePrintDocument_PrintPage
End Class
这篇关于vsprinter中的Richtextbox打印的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文