Reputation: 314
I have a Panel where the contents are added dynamically and exported as an image file. I export the content as image using the following code below.
Bitmap tempBmp = new Bitmap(pnlCanvas.Width, pnlCanvas.Height);
pnlCanvas.DrawToBitmap(tempBmp, new Rectangle(0, 0, pnlCanvas.Width, pnlCanvas.Height));
tempBmp.Save(fileName);
In a particular case i have a RichTextBox control added to the panel. I found that the control is not seen when exported.
I am not sure what goes wrong. Please guide me what should be done.
Thanks in Advance, K
Upvotes: 1
Views: 232
Reputation: 314
Just succeeded with exactly what i was looking for. I am answering my own question so that it could help someone looking for the same.
Sample code to capture the ActiveX controls and Export as Image.
Rectangle ctrlRect = myControl.RectangleToScreen(myControl.ClientRectangle);
Bitmap myImage = new Bitmap(ctrlRect.Width,ctrlRect.Height,PixelFormat.Format32bppArgb);
Graphics myGraphics = Graphics.FromImage(myImage);
myGraphics.CopyFromScreen(ctrlRect.Location, Point.Empty, myControl.Size);
myImage.Save("sample.png");
Upvotes: 0
Reputation: 1197
As it is stated MSDN DrawToBitmap doesn't work with RichTextBox
. Try painting the content using GDI+ manually.
Upvotes: 3
Reputation: 117
Check if the control is actually there, is it disposed or just invisible. Try adding some value to it and check if it returns the value with variable or gives you error (if it's gone). That's my ideas :)
Upvotes: 0