How can I save a Panel in my form as a picture?

可紊 提交于 2019-12-04 10:13:56

Control.DrawToBitMap is still supported in .Net 4. With the following caveats.

From above link:

  • The DrawToBitmap method is not supported for ActiveX controls. You can override the OnPrint event and provide custom printing logic if required.

The DrawToBitmap method has the following limitations:

  • An ArgumentException might be thrown for large bitmaps. The maximum allowable size varies by machine.
  • DrawToBitmap does not support the Ink controls for the Windows XP Tablet PC Edition 2005 operating system.
  • DrawToBitmap does not draw a child TextBox if the Visible property of the TextBox is set to false.
  • Controls inside containers are rendered in reverse order.
  • DrawToBitmap is not fully functional for the RichTextBox; only the border of a bitmap is drawn.

Edit Added example and image:

Bitmap bmp = new Bitmap(panel1.Width,panel1.Height);
panel1.DrawToBitmap(bmp, panel1.Bounds);
bmp.Save(@"C:\Temp\Test.bmp");

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!