下面是我的例程,它工作正常,但例程没有生成包含标题栏的窗口图像。所以请指导我在代码中需要更改的内容。
protected override void WndProc(ref Message m)
{
if (m.Msg == WM_COMMAND && m.WParam.ToInt32() == SC_MINIMIZE)
{
OnMinimize(EventArgs.Empty);
}
base.WndProc(ref m);
}
protected virtual void OnMinimize(EventArgs e)
{
Rectangle r = this.RectangleToScreen(ClientRectangle);
if (_lastSnapshot == null)
{
_lastSnapshot = new Bitmap(r.Width, r.Height);
}
using (Image windowImage = new Bitmap(r.Width, r.Height))
using (Graphics windowGraphics = Graphics.FromImage(windowImage))
using (Graphics tipGraphics = Graphics.FromImage(_lastSnapshot))
{
windowGraphics.CopyFromScreen(new Point(r.Left, r.Top), new Point(0, 0), new Size(r.Width, r.Height));
windowGraphics.Flush();
tipGraphics.DrawImage(windowImage, 0, 0, r.Width, r.Height);
}
}
更新
您的代码有效,但左上角的某些部分不行。所以在这里我上传我使用你的代码生成的图像。请看一下并告诉我我需要在代码中修复什么。表单宽度不正确。谢谢
更新
Bitmap bmp = new Bitmap(this.Width, this.Height);
this.DrawToBitmap(bmp, new Rectangle(Point.Empty, bmp.Size));
bmp.Save(@"d:\Zapps.bmp", ImageFormat.Bmp);