首页 > > > WPF无法通过窗口句柄获取到窗体内的内容
需要把WPF的一个窗口所展示的内容保存为一张图片存放到本地,要求窗口无论是显示还是隐藏都需要获取到内容进行保存。我的WPF相关内容是放在Winfrom的ElementHost控件中,通过ElementHost的Paint事件,拿到句柄保存的图片的空白的。
功能核心代码如下:
System.Windows.Forms.Integration.ElementHost.Paint += new System.Windows.Forms.PaintEventHandler(this.ContentViewControl_OnPaint);
private void ContentViewControl_OnPaint(object sender, System.Windows.Forms.PaintEventArgs e)
{
Bitmap bit = new Bitmap(800, 600);
e.Graphics.DrawImage(bit, new System.Drawing.Point(0, 0));
bit.Save("D:\1.png");
}
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/1978/viewspace-3168024/ ,如需转载,请注明出处,否则将追究法律责任。