我如何显示“正在加载 ...请稍等"Winforms 中的长加载表单消息? [英] How do I show a "Loading . . . please wait" message in Winforms for a long loading form?

查看:46
本文介绍了我如何显示“正在加载 ...请稍等"Winforms 中的长加载表单消息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个很慢的表单,因为表单上放置了很多控件.

I have a form that is very slow because there are many controls placed on the form.

因此,加载表单需要很长时间.

As a result the form takes a long time to loaded.

如何先加载表单,然后显示它,然后在加载延迟时显示另一个带有正在加载...请稍候.?"等消息的表单

How do I load the form first, then display it and while loading delay show another form which that have message like "Loading... please wait.?"

推荐答案

使用单独的线程来显示简单的请等待消息是过度的,尤其是如果您没有太多线程经验.

Using a separate thread to display a simple please wait message is overkill especially if you don't have much experience with threading.

更简单的方法是创建一个请稍候"表单,并在缓慢加载表单之前将其显示为无模式窗口.主窗体加载完成后,隐藏请稍候窗体.

A much simpler approach is to create a "Please wait" form and display it as a mode-less window just before the slow loading form. Once the main form has finished loading, hide the please wait form.

通过这种方式,您只需使用一个主 UI 线程来首先显示请等待表单,然后加载您的主表单.

In this way you are using just the one main UI thread to firstly display the please wait form and then load your main form.

这种方法的唯一限制是您的请等待表单不能动画(例如动画 GIF),因为线程正忙于加载您的主表单.

The only limitation to this approach is that your please wait form cannot be animated (such as a animated GIF) because the thread is busy loading your main form.

PleaseWaitForm pleaseWait=new PleaseWaitForm ();

// Display form modelessly
pleaseWait.Show();

//  ALlow main UI thread to properly display please wait form.
Application.DoEvents();

// Show or load the main form.
mainForm.ShowDialog();

这篇关于我如何显示“正在加载 ...请稍等"Winforms 中的长加载表单消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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