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

查看:115
本文介绍了我如何显示“正在加载”。 。 。请等待” 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.

我如何首先加载表格,然后显示它,而在加载延迟时显示另一张表格,其中显示正在加载...请稍候。 p>

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.

一种更简单的方法是创建一个 Please wait表单,并在缓慢加载表单之前将其显示为无模式窗口。一旦主表单完成加载,就隐藏请等待表单。

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天全站免登陆