Hier een manier om je richtextbox te printen.
Als je uit gebreider wil kan dat ook laat maar horen.
Code:
Public Class Form1
Private Sub PrintDocument1_PrintPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
'PrintPage is the foundational printing event. This event gets fired for every
' page that will be printed
Static intCurrentChar As Int32
Dim font As New Font("Verdana", 14)
Dim PrintAreaHeight, PrintAreaWidth, marginLeft, marginTop As Int32
With PrintDocument1.DefaultPageSettings
PrintAreaHeight = .PaperSize.Height - .Margins.Top - .Margins.Bottom
PrintAreaWidth = .PaperSize.Width - .Margins.Left - .Margins.Right
marginLeft = .Margins.Left
marginTop = .Margins.Top
' X and Y coordinate
End With
If PrintDocument1.DefaultPageSettings.Landscape Then
Dim intTemp As Int32
intTemp = PrintAreaHeight
PrintAreaHeight = PrintAreaWidth
PrintAreaWidth = intTemp
' if the user selects landscape mode, swap the printing area height and width
End If
Dim intLineCount As Int32 = CInt(PrintAreaHeight / font.Height)
Dim rectPrintingArea As New RectangleF(marginLeft, marginTop, PrintAreaWidth, PrintAreaHeight)
Dim fmt As New StringFormat(StringFormatFlags.LineLimit)
Dim intLinesFilled, intCharsFitted As Int32
e.Graphics.MeasureString(Mid(RichTextBox1.Text.ToString, intCurrentChar + 1), font, New SizeF(PrintAreaWidth, PrintAreaHeight), fmt, intCharsFitted, intLinesFilled)
e.Graphics.DrawString(Mid(RichTextBox1.Text.ToString, intCurrentChar + 1), font, Brushes.Black, rectPrintingArea, fmt)
intCurrentChar += intCharsFitted
e.HasMorePages = False
intCurrentChar = 0
End Sub
Private Sub PrintToolStripButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PrintToolStripButton.Click
Try
PrintPreviewDialog1.ShowDialog()
Catch es As Exception
MessageBox.Show(es.Message)
End Try
End Sub
Private Sub SelecteerPrinterToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SelecteerPrinterToolStripMenuItem.Click
PrintDialog1.ShowDialog()
End Sub
Private Sub KiesEenLetterTypeToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles KiesEenLetterTypeToolStripMenuItem.Click
FontDialog1.ShowColor = True
FontDialog1.Font = RichTextBox1.Font
FontDialog1.Color = RichTextBox1.ForeColor
If FontDialog1.ShowDialog() <> DialogResult.Cancel Then
RichTextBox1.Font = FontDialog1.Font
RichTextBox1.ForeColor = FontDialog1.Color
End If
End Sub
Dim fs
Dim Createtext
Private Sub SaveToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SaveToolStripMenuItem.Click
Dim saveFileDialog1 As New SaveFileDialog()
saveFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*"
saveFileDialog1.FilterIndex = 2
saveFileDialog1.RestoreDirectory = True
saveFileDialog1.AddExtension = True
saveFileDialog1.OverwritePrompt = True
saveFileDialog1.DefaultExt = ".txt"
If saveFileDialog1.ShowDialog() = DialogResult.OK Then
Dim sw As New System.IO.StreamWriter(saveFileDialog1.OpenFile)
If Not (sw Is Nothing) Then
sw.Write(RichTextBox1.Text)
End If
sw.Close()
End If
End Sub
End Class