如何在我的主窗体中显示处理窗体
我想在主窗体工作时以窗体显示处理图像。
我已经创建了处理表格。
我尝试用
ProcessingForm obj = new ProcessingForm();
obj.show();
DOSomeStuff();
obj.close();
它显示处理形式..但有时它变得没有响应...或者我的 gif 图像停止动画。
怎么办?
I want to show processing image in form when my main form is working.
I have created processing form .
I tried it with
ProcessingForm obj = new ProcessingForm();
obj.show();
DOSomeStuff();
obj.close();
it shows processing form..but some time it becomes not responding...or my gif image stops animating.
How to do that??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用
BackgroundWorker
类来分离在表单消息处理和处理代码(如DoSomeStuff()
)下工作的进程。如果您想知道DoSomeStuff()
的进度,您可以在后台工作程序中实现它,因为此类支持它。但是,如果您的环境对实时处理这两件事的速度很慢,您必须给您的BackgroundWorker一些最低的优先级,然后您的图像可以实时工作,但您的东西可以做更长的时间。 这不是一个好的解决方案,因为取决于环境。
You can use
BackgroundWorker
class to separate process working under Form Messages processing and Processing your code likeDoSomeStuff()
. If you want know what progress of yourDoSomeStuff()
was done, you can implemend in your background worker this because this class support it.But if your enviroment is to slow to getting this 2 things processing in realtime, you must give your BackgroundWorker some lowest priority then your image can be working in realtime but your stuff doing longer. This is not good solution because depends on enviromen.
我使用了 CodeProject 中的此代码。这是一个类似于 Firefox 使用的“旋转”计时器动画。
将 dll 添加为项目的引用,并将进度指示器拖放到表单上。
将其初始状态设置为不可见。
然后,当您想要显示处理调用时:
要在处理完成时删除它,调用:
它使用 System.Windows.Forms.Timer 来控制动画并覆盖 OnPaint code> 方法绘制旋转图像。这可能与您需要的一样准确。
我不是作者,但我已经使用过它,并且没有遇到任何问题,它会明显减慢实际进程。
但是,您必须将处理放到另一个线程上 - 使用
BackgroundWorker
类,否则 UI 将不会更新。I've used this code from CodeProject. It's a "rotating" timer animation similar to that used by Firefox.
Add the dll as a reference to your project and drop the progress indicator on your form.
Set it's initial state to be invisible.
Then when you want to show your processing call:
To remove it when the processing is complete call:
It uses a
System.Windows.Forms.Timer
to control the animation and overrides theOnPaint
method to draw the image rotating. This is probably as accurate as you would need.I'm not the author, but I have used this and not had any problems with it slowing the actual processes down appreciably.
However, you will have to put your processing onto another thread - use the
BackgroundWorker
class, otherwise the UI won't update.