ajtech
asked on
How to print a Rich Text Box or BMP to a VB.NET PrintDocument
I am trying to generate a report using VB.NET.
I can easily use Drawstring to place text on the Print Document.
But I am not sure how to define a square where a rich text box can be located on the print document and printed
I can easily use Drawstring to place text on the Print Document.
But I am not sure how to define a square where a rich text box can be located on the print document and printed
ASKER
Ok that is fine, but that is not what I wanted.
I want to print a Rich Text Box
I want to print a Rich Text Box
DO you want to print content of RTB?
ASKER
yes
I want to create a rectangle somewhere on the printdocument and print the properly formatted rich text contents
I want to create a rectangle somewhere on the printdocument and print the properly formatted rich text contents
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:
Answered by iboutchkine
Please leave any comments here within the next seven days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
TheLearnedOne
EE Cleanup Volunteer
I will leave a recommendation in the Cleanup topic area that this question is:
Answered by iboutchkine
Please leave any comments here within the next seven days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
TheLearnedOne
EE Cleanup Volunteer
'label, picture and 4 buttons
Option Explicit On
Option Strict On
Public Class Form1
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
#End Region
#Region "Variables"
Private printWholeForm As Boolean = False
Private memImage As Bitmap
#End Region
#Region "Base Events"
Private Sub print_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles printGraphic.Click, PrintForm.Click
Dim buttonID As Button = CType(sender, Button)
If buttonID.Name = "printForm" Then
printWholeForm = True
Call BuildFormImage()
End If
PrintDialog1.Document = PrintDocument1
If PrintDialog1.ShowDialog = DialogResult.OK Then
PrintDocument1.Print()
End If
End Sub
Private Sub printPreview_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles printPreviewGraphics.Click
Dim buttonID As Button = CType(sender, Button)
Dim PrintPreviewID As New PrintPreviewDialog()
PrintPreviewID.Document = PrintDocument1
If buttonID.Name = "printPreviewForm" Then
printWholeForm = True
Call BuildFormImage()
End If
If PrintPreviewID.ShowDialog = DialogResult.OK Then
PrintDocument1.Print()
End If
End Sub
Private Sub PrintDocument1_PrintPage(B
Dim formGraphics As Graphics = e.Graphics
If printWholeForm = False Then
' Build each part of the picture
With formGraphics
.DrawString(Label1.Text, Label1.Font, New SolidBrush(Label1.ForeColo
.DrawImage(PictureBox1.Ima
.Dispose()
End With
Else
formGraphics.DrawImage(mem
memImage.Dispose()
formGraphics.Dispose()
printWholeForm = False
End If
e.HasMorePages = False
End Sub
#End Region
#Region "Implementation Methods"
Private Sub BuildFormImage()
Dim graphicID As Graphics = Me.CreateGraphics
Dim sizeID As Size = Me.Size
Const SRCCOPY As Integer = &HCC0020
memImage = New Bitmap(sizeID.Width, sizeID.Height, graphicID)
Dim memGraphic As Graphics = graphicID.FromImage(memIma
Dim deviceContext1 As IntPtr = graphicID.GetHdc
Dim deviceContext2 As IntPtr = memGraphic.GetHdc
BitBlt(deviceContext2, 0, 0, Me.ClientRectangle.Width, Me.ClientRectangle.Height,
graphicID.ReleaseHdc(devic
memGraphic.ReleaseHdc(devi
End Sub
Private Declare Auto Function BitBlt Lib "gdi32.dll" (ByVal hdcDest As IntPtr, ByVal _
nXDest As Integer, ByVal nYDest As Integer, ByVal nWidth As Integer, ByVal nHeight _
As Integer, ByVal hdcSrc As _
IntPtr, ByVal nXSrc As Integer, _
ByVal nYSrc As Integer, ByVal _
dwRop As System.Int32) As Boolean
#End Region
End Class