14

I want a user to be able to drag a Control while showing it. I can't seem to find a way to convert its appearance to an image (in order to convert that image into an icon in order to have that as the dragging icon).

ispiro
  • 26,556
  • 38
  • 136
  • 291

1 Answers1

35

If I understand correctly, you want to draw the control to an image? Use Control.DrawToBitmap:

Bitmap b = new Bitmap(myControl.Width, myControl.Height);
myControl.DrawToBitmap(b, new Rectangle(0, 0, b.Width, b.Height));
Ry-
  • 218,210
  • 55
  • 464
  • 476
  • I find it odd that a couple of searches didn't get me this simple answer, and one of them even said it can't be done in C# (perhaps it's from an earlier version of .net). – ispiro Apr 16 '12 at 19:22
  • hi @minitech, sorry I know is long, but I would like to ask is it possible to use this for AjaxControlToolkit control? – Felicia Soh Oct 22 '15 at 02:18
  • @FeliciaSoh: This is about Windows Forms. It doesn’t apply to ASP.NET at all. Sorry! – Ry- Oct 22 '15 at 02:57
  • @minitech, oh I see..ok thanks for your reply! I will think of other solution. – Felicia Soh Oct 22 '15 at 03:01