我如何显示等待表格 [英] How Do I Show Waiting Form

查看:75
本文介绍了我如何显示等待表格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的,

我在Windows窗体中工作使用c#

i的应用程序想要制作等待表格,这应该在鼠标点击期间出现事件执行时间



当我点击一个按钮时,首先出现等待表格,然后在点击事件中执行代码,在点击事件结束时等待表格应该消失



注意,

i想要系统中的这个foreach按钮,我不想在应用程序中找到每个按钮并在Start和in中添加代码每次点击活动结束



亲切的建议



谢谢



Mohammed AlMaghraby

Dears,
i'm working in windows forms Application using c#
i want to make Waiting form which should appear during the mouse click Event Execution time
i.e
when i click a button,first the Waiting form appear and then execute the code in the click event and at the end of the click event the waiting form should disappear

note,
i want this foreach button in the system and i don't want to find each button in the application and add code in the Start and in the end of each click event

kindly advice

thanks

Mohammed AlMaghraby

推荐答案

没有办法像你所描述的那样全球化。



您无法在事件处理程序中显示表单,执行工作以及销毁表单。你的表格要么根本不显示,要么可能不完全自我画。



为什么?因为你有UI线程忙着做东西所以它不能处理WM_PAINT消息,直到你的事件处理程序返回之后。



你必须移动你的工作到后台线程。您的事件处理程序可以调用创建并显示表单的方法,并设置要完成的工作并启动工作线程。然后UI线程可以自由地提取消息。



当工作线程完成时,它必须通知UI线程工作完成,以便忙表格可以拆除。



Google为C#BackgroundWorker提供了一种方法。
There is no way to do it globally like you've described.

You can NOT show the form, do your work, and the destroy the form all in your event handler. You're form will either not show up at all or may not entirely paint itself.

Why? Because you've got the UI thread busy doing stuff so it can't process the WM_PAINT messages coming in until after your event handler returns.

You have to move your work to a background thread. Your event handler can call a method that creates and shows the form and setups up the work to be done and kicks off the worker thread. The UI thread will then be free to pump messages.

When the worker thread completes it has to notify the UI thread that the work is done so that the "busy" form can be torn down.

Google for "C# BackgroundWorker" for one method of doing this.


这篇关于我如何显示等待表格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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