Capture Image of Control to Clipboard


M

MCM

How do I capture an Image (Bitmap) of one of my controls (in a Windows Form
App) and place it on the clipboard in C#?

Thanks,

- M
 
Ad

Advertisements

M

Marc Gravell

Well, I've never had to try it, but the following seems to work:

private static void CopyControl(Control target)
{
if (target == null) throw new
ArgumentNullException("target");
using (Bitmap bmp = new Bitmap(target.Width,
target.Height))
{
target.DrawToBitmap(bmp, new Rectangle(new Point(0,0),
target.Size));
Clipboard.SetImage(bmp);
}
}

I stress that I don't know if there are any problems using this
approach...

Marc
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top