Form.Hide 不会阻止表单包含在屏幕转储中
Form.Hide does not prevent form from being included in screen dump
问题
我正在使用以下代码执行屏幕转储。即使我用 this.Hide
隐藏了表单本身,该表单仍包含在屏幕转储中,我不希望它成为这样。
this.Hide(); //Hide to not include this form in the screen dump
try
{
Rectangle bounds = Screen.GetBounds(Point.Empty);
using (Bitmap bitmap = new Bitmap(bounds.Width, bounds.Height))
{
using (Graphics g = Graphics.FromImage(bitmap))
{
g.CopyFromScreen(Point.Empty, Point.Empty, bounds.Size);
}
bitmap.Save(fileName, ImageFormat.Png);
}
}
catch (Exception exc)
{
MessageBox.Show(LanguageMessages.MsgTextErrorScreenDump +
Utilities.DoubleNewLine() + exc.ToString(),
LanguageMessages.MsgCaptionErrorScreenDump,
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
finally
{
this.Show(this.Owner);
}
我试过的:
隐藏表格后添加以下内容,没有任何区别:
- 睡觉(1000);
- this.Repaint();
- this.Invalidate();
我的问题是:
为什么 this.Hide
没有真正隐藏表单,从而防止它被包含在上面代码的屏幕转储中?
您可以使用计时器作弊,这会给您足够的 "time" 来隐藏表格:
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();
问题
我正在使用以下代码执行屏幕转储。即使我用 this.Hide
隐藏了表单本身,该表单仍包含在屏幕转储中,我不希望它成为这样。
this.Hide(); //Hide to not include this form in the screen dump
try
{
Rectangle bounds = Screen.GetBounds(Point.Empty);
using (Bitmap bitmap = new Bitmap(bounds.Width, bounds.Height))
{
using (Graphics g = Graphics.FromImage(bitmap))
{
g.CopyFromScreen(Point.Empty, Point.Empty, bounds.Size);
}
bitmap.Save(fileName, ImageFormat.Png);
}
}
catch (Exception exc)
{
MessageBox.Show(LanguageMessages.MsgTextErrorScreenDump +
Utilities.DoubleNewLine() + exc.ToString(),
LanguageMessages.MsgCaptionErrorScreenDump,
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
finally
{
this.Show(this.Owner);
}
我试过的: 隐藏表格后添加以下内容,没有任何区别:
- 睡觉(1000);
- this.Repaint();
- this.Invalidate();
我的问题是:
为什么 this.Hide
没有真正隐藏表单,从而防止它被包含在上面代码的屏幕转储中?
您可以使用计时器作弊,这会给您足够的 "time" 来隐藏表格:
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();