1

Trying to implement stylus writing on a windows form. I'm trying this example from codeproject.

I need to capture what ever user has wrote on the forms control. I have tried the following code

Bitmap bmp = new Bitmap(gbTestArea.Width, gbTestArea.Height);
Graphics g = Graphics.FromImage(bmp);
g.CopyFromScreen(PointToScreen(gbTestArea.Location), new Point(0, 0), gbTestArea.Size);

gbTestArea.DrawToBitmap(bmp, new Rectangle(0, 0, bmp.Width, bmp.Height));
bmp.Save(@"c:\someImage.Jpeg", ImageFormat.Jpeg);

But the problem is its not spitting out what ever was written on the form, it show only the empty control(group box in this example). My final goal is to capture what ever user has written on the forms control. Any suggestion will be appreciated, thanks in advance.

Reza Aghaei
  • 120,393
  • 18
  • 203
  • 398
3not3
  • 516
  • 1
  • 7
  • 18
  • You should put drawing logic in `OnPaint` method. Otherwise you will not see drawings when you use `DrawToBitmap`. You may find [this post](http://stackoverflow.com/a/38297293/3110834) about freehand drawing useful. Also you don't need to copy image from screen to the bitmap and then draw your control on the bitmap again. Using `DrawToBitmap` would be enough. – Reza Aghaei Oct 30 '16 at 14:37
  • In fact, you can draw on the Bitmap directly and then you even don't need `DrawToBitmap`. – Reza Aghaei Oct 30 '16 at 17:11

0 Answers0