您可以使用计时器进行作弊,这将给您足够的“时间”来隐藏表单:
private System.Windows.Forms.Timer hideTimer = null;
整整一秒钟似乎就足够了:
this.Hide();
hideTimer = new System.Windows.Forms.Timer() { Interval = 1000 };
hideTimer.Tick += (ts, te) => {
hideTimer.Stop();
hideTimer.Dispose();
Rectangle bounds = Screen.GetBounds(this);
using (Bitmap bitmap = new Bitmap(bounds.Width, bounds.Height)) {
using (Graphics g = Graphics.FromImage(bitmap)) {
g.CopyFromScreen(bounds.Location, Point.Empty, bounds.Size);
}
bitmap.Save(fileName, ImageFormat.Png);
}
this.Show(this.Owner);
};
hideTimer.Start();