Click here to Skip to main content
15,896,727 members
Please Sign up or sign in to vote.
2.50/5 (2 votes)
See more:
Hey I have a large panel in Ribbon Application , size of a page and it contains many other controls and a richtextbox. However DrawToBitmap is not working properly for richtextbox. I searched a little but it seems i have to print the screen. But i can't print because the page is a little big.
So is there another way to draw my panel with the richtextbox?

I am using this code.





C#
OuterPages outer=new OuterPages();
Controls.Add(outer.TestPage);
SaveBitmap();
//OuterPage is a class that contaings the panel TesPage and many controls in it //including RichTextBox.
       public void DrawControl(Control control, Bitmap bitmap)
        {
            control.DrawToBitmap(bitmap, control.Bounds);
            foreach (Control childControl in control.Controls)
            {
                DrawControl(childControl, bitmap);
            }
        }

        public void SaveBitmap()
        {
            Rectangle rc = new Rectangle(0, 0, outer.TestPage.Width, outer.TestPage.Height);
            Bitmap bmp = new Bitmap(outer.TestPage.Width, outer.TestPage.Height);
            
            outer.TestPage.DrawToBitmap(bmp, rc);
            foreach (Control control in outer.TestPage.Controls)
            {
                DrawControl(control, bmp);
            }
          //  outer.TitleRichTextBox.DrawToBitmap(bmp, rc);  This is not working.

            bmp.Save("C:\\Users\\Missak\\Desktop\\panel.jpg");
        }
Posted
Updated 8-Feb-13 0:21am
v4
Comments
Sergey Alexandrovich Kryukov 2-Feb-13 17:43pm    
Why?! And what is "not working properly", exactly?
—SA
missak boyajian 7-Feb-13 15:11pm    
RichTextBox does not have DrawToBitmap method. How can I draw it?
missak boyajian 3-Feb-13 5:58am    
The text is not showing. It is just drawing the border.
Sergey Alexandrovich Kryukov 7-Feb-13 15:32pm    
This is not a complete code sample. What is, for example, outer? You could abstract it out, for example, some function without any unknown definitions, if not a complete project — the problem is simple enough.
Is it System.Windows.Forms? Always tag your UI library or application type...
—SA
missak boyajian 8-Feb-13 6:25am    
It's ribbon application. I have download it from component one studio. I improved the question. If still not enough I can improve it.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900