我的代码如下:
private void button1_Click(对象发送者,EventArgs e){For (int I = 1;我& lt;Application.OpenForms.Count;我+ +){如果(Application.OpenForms[我]。WindowState == formwindowstate . minimize){
Application.OpenForms[i].WindowState = FormWindowState.Normal; using (var bmp = new Bitmap(Application.OpenForms[i].Width, Application.OpenForms[i].Height)) { Application.OpenForms[i].DrawToBitmap(bmp, new Rectangle(0, 0, bmp.Width, bmp.Height)); bmp.Save(@"d:Duong" + Application.OpenForms[i].Text + ".png"); } Application.OpenForms[i].WindowState = FormWindowState.Minimized; } else { using (var bmp = new Bitmap(Application.OpenForms[i].Width, Application.OpenForms[i].Height)) { Application.OpenForms[i].DrawToBitmap(bmp, new Rectangle(0, 0, bmp.Width, bmp.Height)); bmp.Save(@"d:Duong" + Application.OpenForms[i].Text + ".png"); } } } }
之前每个应用程序。OpenForms[i]有一个MdiParent。当其中一些被最小化,一些被激活时,我点击一个按钮来获取快照,我得到了每个表单的所有图片。但是任何最小化的表单在返回最小化之前都会闪烁。我知道问题是来自WindowState,但是如果它不显示,我怎么能得到快照?请帮助我,我看到了关于API GDI+的话题。但它们是用于最小化窗口的应用,我现在需要的是我的窗体和它的孩子。由于
所有最小化窗口的截图。
private void button1_Click(object sender, EventArgs e)
{
//MessageBox.Show(string.Format("{0}", Application.OpenForms.Count));
System.Collections.IEnumerator myEnumerator = Application.OpenForms.GetEnumerator();
while (myEnumerator.MoveNext())
{
Form current = (Form)myEnumerator.Current;
if (current.WindowState == FormWindowState.Minimized )
{
current.WindowState = FormWindowState.Normal;
current.Activate();
Application.DoEvents();
using (var bmp = new Bitmap(current.Width, current.Height))
{
current.DrawToBitmap(bmp, new Rectangle(0, 0, bmp.Width, bmp.Height));
bmp.Save(@"c:tempchildwindows" + current.Text + ".png");
}
}
}
}
希望这对你有帮助。致以最亲切的问候。
尝试:
- 挂件图
- 采取快照
- 简历表格绘制
你可以使用SendMessage和WM_SETREDRAW暂停/恢复绘图。
在For循环之前暂停控件绘制,并在代码结束时恢复绘制。我建议使用Try/Catch块,并在最后部分包含简历绘图。
暂停绘图:
SendMessage(ctrlControl.Handle, WM_SETREDRAW, 0, 0)
恢复绘图:
SendMessage(ctrlControl.Handle, WM_SETREDRAW, 1, 0)
ctrlControl.Refresh()
ctrlControl可以是任何控件:在您的情况下,我建议使用MDI容器
这将恢复最小化的窗口,并对所有其他拥有的应用程序窗口进行快照。
private void button1_Click(object sender, EventArgs e)
{
System.Collections.IEnumerator myEnumerator = Application.OpenForms.GetEnumerator();
while (myEnumerator.MoveNext())
{
Form current = (Form)myEnumerator.Current;
if (current.WindowState == FormWindowState.Minimized)
{
current.WindowState = FormWindowState.Normal;
current.Activate();
Application.DoEvents();
SaveToFile(current);
current.WindowState = FormWindowState.Minimized;
Application.DoEvents();
}
else
{
current.Activate();
Application.DoEvents();
SaveToFile(current);
}
}
}
private void SaveToFile(Form form)
{
using (var bmp = new Bitmap(form.Width, form.Height))
{
form.DrawToBitmap(bmp, new Rectangle(0, 0, bmp.Width, bmp.Height));
bmp.Save(@"c:tempchildwindows" + form.Text + ".png");
}
}
希望这将帮助。问候。