tags:

views:

27

answers:

1

I want to 'grab' the image of a control on my winforms dialog. I can access the 'graphics' context for the control using:

MyControl.CreateGraphics()

But how do i copy a rectangle from that graphics context to an image, or a bitmap, or call getpixel on it?

Thanks a lot.

A: 

I think MyControl.DrawToBitmap is the way to go:

Bitmap bmp = new Bitmap(MyControl.Width, MyControl.Height);
MyControl.DrawToBitmap(bmp, MyControl.ClientRectangle);

If you need to get the pixels then use Bitmap.GetPixel or Bitmap.LockBits

GarethOwen