Hi,
I was able to capture the picture of the richtextbox by following code snippet. i think it may be of your use also.
private void ShowBitmap_btn_Click(object sender, RoutedEventArgs e)
{
if (MyTextBox_txt == null)
return;
Rect _descendentBounds = VisualTreeHelper.GetDescendantBounds(MyTextBox_txt);
//RenderTargetBitmap _targetBitmap = new RenderTargetBitmap((Int32)_descendentBounds.Width,
// (Int32)_descendentBounds.Height,
// 96, 96, PixelFormats.Pbgra32);
Rect _tempRect = new Rect(System.Windows.Forms.Screen.PrimaryScreen.Bounds.X,
System.Windows.Forms.Screen.PrimaryScreen.Bounds.Y,
System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width,
System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height);
RenderTargetBitmap _targetBitmap = new RenderTargetBitmap((Int32)_tempRect.Width,
(Int32)_tempRect.Height,
96, 96, PixelFormats.Pbgra32);
DrawingVisual _drawingVisual = new DrawingVisual();
using (DrawingContext _drwaingContext = _drawingVisual.RenderOpen())
{
VisualBrush _visualBrush = new VisualBrush(MyTextBox_txt);
_drwaingContext.DrawRectangle(_visualBrush, null, new Rect(new Point(), _tempRect.Size));
}
_targetBitmap.Render(_drawingVisual);
PngBitmapEncoder _png = new PngBitmapEncoder();
_png.Frames.Add(BitmapFrame.Create(_targetBitmap));
Stream _fileStream;
_fileStream = File.Create(@"E:\sample1.png");
_png.Save(_fileStream);
System.Drawing.Bitmap _tempBitmap = new System.Drawing.Bitmap(_fileStream);
_tempBitmap.Save(@"E:\sample1.bmp");
_fileStream.Close();
_fileStream.Dispose();
}