设置表的家长 [英] Set the Parent of a Form

查看:140
本文介绍了设置表的家长的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Windows窗体从中我想开一个状态表,上面写着保存完成后,正在保存...
,然后在前看不见。我想在调用形式的中间市中心的小型状态表。我试过设置中StartPosition属性格式为CenterParent,但它行的事工作。我创建从其他形式的地位形式像这样:

I have a Windows form from which I would like to open a status form that says "Saving..." and then disapears when the saving is complete. I would like to center this small status form in the middle of the calling form. I've tried setting the "StartPosition" propery to "CenterParent", but it doest work. I create the status form from the other form like so:

SavingForm saving = new SavingForm();
savingForm.Show();
Thread.Sleep(500); //Someone said this is bad practice ... why?
savingForm.Close();



岂不调用形式是父?
当我设置监视保存它说,它没有父

Wouldn't the calling form be the "Parent"? When I set a watch for saving it says it has no parent.

我试过:

SavingForm saving = new SavingForm();
saving.Parent = this;
savingForm.Show();
Thread.Sleep(500);
savingForm.Close();

和它抛出一个异常顶级控件不能被添加到一个控制。

and it throws an exception "Top-level control cannot be added to a control."

我如何在呼叫窗口中心这个状态窗口?

How do I center this status window in the calling window?

感谢

推荐答案

我会做这样的事情:

SavingForm saving = new SavingForm();
savingForm.ShowDialog(this);

在SavingForm我将开始在500毫秒运行负载处理一个计时器,然后关闭窗体当完成。清洁的方式。的ShowDialog也会锁定您的用户界面只显示储蓄的形式,而不是让用户猴子什么。

In SavingForm i would start a timer in the load handler that runs for 500 milliseconds and then closes the form when done. Cleaner that way. ShowDialog will also lock your UI to only display the saving form and not allow the user to monkey with anything.

这篇关于设置表的家长的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆