WinForms:寻找一种简单的方法来弹出“正在处理..”控制板

发布于 2024-11-28 16:35:20 字数 218 浏览 0 评论 0原文

我有一个 WinForms 应用程序,在某些时候,它会执行一些需要几秒钟的计算。在此期间,我禁用了控件。此外,我想显示一个弹出窗口,更明显地“阻止”应用程序。

我尝试在表单顶部放置一个面板来执行此操作,但不知何故我无法向其中添加任何文本。即我放在那里的标签和图像框不知何故没有显示或位于面板后面。

有什么建议我可以如何以快速而简单的方式实现这一目标? ..我的意思是,无需重新设计整个表格。

I have a WinForms application that, at some point, will do some calculations that take a couple of seconds. During this time, I disable the controls. Additionally I want to display a popup that kind of 'blocks' the application more visibly.

I tried placing a Panel on top of the Form in order to do so, but there I'm somehow not able to add any text to it. I.e. the Labels and ImageBoxes I put there are somehow not displayed or behind the Panel.

Any suggestions how I could achieve this in a quick and easy way? .. I mean, without redesigning the whole Form.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

初雪 2024-12-05 16:35:20

您的附加面板中未显示的内容的问题是,所有内容都在同一线程中发生,但您的计算阻止了所有内容的出现,因为它们占用了线程。您应该考虑使用backgroundWorker,它是WinForms 中的工具之一。您应该将执行计算的函数调用放入backgroundWorker的DoWork方法中,然后表单本身可以在计算期间继续运行。

请参阅 http://msdn .microsoft.com/en-us/library/cc221403%28v=vs.95%29.aspx 例如

Your problem with the things not showing up in your additional panel is that everything is happening in the same thread, but your calculations are blocking everything from appearing because they are hogging up the thread. You should look into using a backgroundWorker, which is one of the tools in WinForms. You should throw the function call that performs the calculations into the DoWork method of the backgroundWorker, then the form itself can continue to function during the calculations.

See http://msdn.microsoft.com/en-us/library/cc221403%28v=vs.95%29.aspx for examples

你是年少的欢喜 2024-12-05 16:35:20

创建一个在处理过程中弹出的对话框(Windows窗体),然后您可以在处理完成后关闭该对话框。

通过使用对话框而不是消息框,您仍然可以在处理完成后控制关闭窗口。

Create a Dialog Box (windows form) to popup during the processing, then you can have the Dialog Box close once your processing is completed.

By using a Dialog Box not a Message Box, you can still have control over closing the window when your processing is done.

心清如水 2024-12-05 16:35:20

您可以创建一个简单的 UserControl,仅包含一个 Label 和一个 ImageBox,也许还可以使用它们的值的公共设置器。您可以将其添加到表单中,将其 Visible 属性设置为 false。然后您可以在计算过程中使其可见,并最终返回顶部不可见。

You could create a simple UserControl with just a Label and an ImageBox, maybe with public setter for their values. You can add it to your form setting its Visible property to false. Then you can make it visible during your calculations and go back top invisible in the end.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文