将控件内容保存成图片,即使控件区域被其它窗口遮挡住也会将整个控件保存下来。
命名空间:
using System.Drawing;
using System.Drawing.Imaging;
using System.Runtime.InteropServices;
API声明:
[DllImportAttribute("gdi32.dll")]
private static extern bool BitBlt(
IntPtr hdcDest,
int nXDest,
int nYDest,
int nWidth,
int nHeight,
IntPtr hdcSrc,
int nXSrc,
int nYSrc,
Int32 dwRop // 处理数值
);
保存方法:
private void SaveControlToImage(Form form, Control control, string path)
{
try
{
Rectangle screenRect = new Rectangle();
screenRect = Screen.GetWorkingArea(form);
Graphics formGrap = form.CreateGraphics();
Image controlImage = new Bitmap(control.Width, control.Height, formGrap);
Graphics controlGrap = Graphics.FromImage(controlImage);
IntPtr fromH