Hi Venkat,
From your descript, you have put several rich text boxes on a form and want to print them together.
Based on my understanding, we can get the images of these rich text boxes and draw these images on one print page in the PrintPage event handler of the PrintDocument.
The code snippet below shows how to get an image of a RichTextBox:
[DllImport("gdi32.dll")]
static extern bool BitBlt(IntPtr hdc, int nXDest, int nYDest, int
nWidth, int nHeight, IntPtr hdcSrc, int nXSrc, int nYSrc, uint dwRop);
//A method to draw a RichTextBox to an image.
private void DrawToBitmap(RichTextBox richTextBox, Bitmap image, Rectangle targetRectangle)
{
Graphics g = richTextBox1.CreateGraphics();
Graphics g2 = Graphics.FromImage(image);
IntPtr gi = g.GetHdc();
IntPtr gi2 = g2.GetHdc();
BitBlt(gi2, 0, 0, richTextBox.Width, richTextBox.Height, gi, 0, 0, 0x00CC0020);
g.ReleaseHdc();
g2.ReleaseHdc();
g.Dispose();
g2.Dispose();
}
The code snippet below shows how to draw the images of several RichTextBoxes:
private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
//Geht the image of the first rich textbox.
Bitmap img1 = new Bitmap(this.richTextBox1.Width,this.richTextBox1.Height);
//Get the location, we need to adjust it based on the page bounds.
Point loc1 = this.richTextBox1.Location;
//Draw the rich textbox.
e.Graphics.DrawImage(img1, loc1);
//Get images of other rich textboxes and draw them.
}
Let me know if this does not help.
Aland Li
Please mark the replies as answers if they help and unmark if they don't. This can be beneficial to other community members reading the thread.