gpt4 book ai didi

c# - Mainform 的屏幕截图显示了子表单。如何确保子表单已关闭?

转载 作者:可可西里 更新时间:2023-11-01 09:59:43 26 4
gpt4 key购买 nike

我想在我的 Mainform 上制作面板的屏幕截图。这个屏幕截图应该是在用户在子表单上选择了一些选项之后制作的。一开始一切顺利,但现在屏幕截图包含部分子表单。

子表单像这样打开:

private void Bexport_Click(object sender, EventArgs e) //button
{
ex = new Export();
initexForm();
ex.FormClosed += this.exFormClosed;
ex.TXTfilename.Focus();
ex.ShowDialog(this);
}

制作截图的函数:

void exFormClosed(object sender, EventArgs e)
{
try
{
System.Drawing.Rectangle bounds = Mainpanel.Bounds;
bounds.Width = bounds.Width - 6;
bounds.Height = bounds.Height - 4;
using (Bitmap bitmap = new Bitmap(bounds.Width, bounds.Height))
{
using (Graphics g = Graphics.FromImage(bitmap))
{
g.CopyFromScreen(
Mainpanel.PointToScreen(new Point()).X + 3,
Mainpanel.PointToScreen(new Point()).Y + 2, 0,
0, bounds.Size);
}

bitmap.Save(Application.StartupPath + temppic.bmp);
Document doc = new Document();
...

我使用了事件 FormClosedFormClosing,两者的结果相似。然后我尝试用 ex.Hide() 隐藏子表单,但它隐藏了整个程序,这意味着屏幕截图显示了程序后面的桌面。

有人知道如何在制作屏幕截图之前确保子表单已关闭吗?

乔纳森

最佳答案

问题可能是主窗体在子窗体关闭后没有时间重新绘制。

this.Update();

将强制表单重绘 ( http://msdn.microsoft.com/en-us/library/system.windows.forms.control.update.aspx )

关于c# - Mainform 的屏幕截图显示了子表单。如何确保子表单已关闭?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18592315/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com