i need to print all the contents of my panel to an image. Everything works, except the Rich Text Box's..

I've checked online and i can't get my head around the code as it is fairly advanced.

is there any 3rd party components that have this function?

i managed to get an image of the control but this isnt what is required as it needs to be added to the panel image in its original X and Y coordinates.

richtextbox.drawstring does work, but not with the textbox's original format, as you need to specify the font, size, colour when you draw it. and my richtexbox may have different colours/size etc in the one string.

any tips or anything becuase i'm really stuck and this is the main function of the application.

if richTextBox.DrawtoBitmap worked, the project would be finished by now.

Thanks for any replies.


public void DrawStringFloat(Bitmap bmp, RichTextBox rtb)
            // Create string to draw.
            String drawString = rtb.Text;

            // Create font and brush.
            Font drawFont = (rtb.Font);
            SolidBrush drawBrush = new SolidBrush(rtb.SelectionColor);

            // Create point for upper-left corner of drawing.
            float x = rtb.Location.X;
            float y = rtb.Location.Y;

            // Draw string to screen.
            using (Graphics g1 = Graphics.FromImage(bmp))
                g1.CompositingMode = CompositingMode.SourceCopy;
                g1.CompositingQuality = CompositingQuality.HighQuality;
                g1.InterpolationMode = InterpolationMode.HighQualityBicubic;
                g1.SmoothingMode = SmoothingMode.AntiAlias;
                g1.TextRenderingHint = TextRenderingHint.AntiAlias;
                g1.DrawString(drawString, drawFont, drawBrush, x, y);

and called by..

DrawStringFloat(bmp, richTextBox1);

this works, not as desired, but now the font is quite larger than the original..

right path? known fixes?..


This question has already been answered. Start a new discussion instead.