在开始流程之前显示表单 [英] Show Form before starting a process

查看:64
本文介绍了在开始流程之前显示表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,



我在开始表格后启动搜索(初始参数等)。

我的问题是在搜索完成之前表单没有显示。



我想打开表单窗口并显示参数,所以在启动搜索之前,只是为了显示用户有什么事情发生。





我打开表格后尝试了按钮并生成按钮点击事件,但是它没有按照我预期的方式工作(只是相同的结果)。



刷新(this.Refresh();)也不起作用。 />




有关如何编程的想法吗?



提前谢谢。



David。

解决方案

有几种方法可以做到这一点:显然最好的方法是用户的观点是以正确的方式进行 - 通过将耗时的操作移动到Ba中ckgroundWorker线程并显示进度。



但是,你可以通过在Form.Shown事件中而不是在Load事件中或在构造函数。可能它不会很好,除非搜索花费很少的时间,并且在所显示的事件(以及所有其他非背景事件)完成处理之前,表格上的控件将不会被绘制 - Paint很低优先操作,直到没有其他事情发生时才会发生。



另一种方法是使用计时器 - 以半秒延迟启动它,并且停止它们他们在事件处理程序中进行长时间的操作。



这两个都会有所作为,但它们对用户POV非常讨厌,因为它们会锁定UI线程直到完成。如果少量的额外工作,BackgroundWorker是一个更好的解决方案。


Hi


保持初始化程序不变;以便首先进行基本表单初始化。



创建一个计时器(将计时器设置为有足够的时间加载表单)并在Form_Load事件中启动计时器。



当计时器第一次打勾时调用你的搜索功能并禁用计时器。



如果你想提高工作效率,你可以利用计时器向用户显示已用时间。





问候

Jegan

Hallo,

I am launching a search just after starting a form (initial parameters and so on).
My problem is that the form is not shown open until the search is finished.

I would like to open the form window and show parameters and so before launching the search, just to show the user that something is going on.


I have tried with a button and generating the button click event after opening the form, but it does not work in the way that I expected (just the same result).

The refresh (this.Refresh();) does not work either.


Any idea about how to program that?

Thank you in advance.

David.

解决方案

There are a couple of ways to do this: clearly the nicest from the user perspective is to do it the "proper" way - by moving the time consuming operation into a BackgroundWorker thread and showing the progress.

However, you can show that something has happened by doing it in the Form.Shown event rather than in the Load event or in the constructor. Probably, it won''t be very good, unless the search takes very little time, and the controls on the form will not be painted until the shown event (and all other non-background events) have finished processing - Paint is a low priority operation and doesn''t happen until there is nothing else going on.

The other method is to use a timer - start it with a half second delay, and stop it them do the long operation in the event handler.

Both of these will do something, but they are quite nasty from a user POV because they will lock up the UI thread until they finish. A BackgroundWorker is a much better solution, if a small amount of extra work for you.


Hi
Leave the initializer alone as they are; so that the basic form initialization will take place first.

Create a timer (set the timer to have enough time to load your form) and start timer in "Form_Load" event.

When the timer ticks on the first time call your search function and disable the timer.

If you want to be more productive, you can make use of the timer to show the elapsed time to the user.


Regards
Jegan


这篇关于在开始流程之前显示表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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