控件通过进度条显示在表单的后面. [英] Controls display late on form with progress bar.

查看:58
本文介绍了控件通过进度条显示在表单的后面.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个简单的应用程序,用于将文件从一个位置复制到另一个位置.它仅包含两种形式:

用户选择源和目的地并单击按钮以开始复制过程的主要形式

带有进度栏,确定和取消按钮的弹出式窗体(frmProgress).

当用户在主窗体上单击复制"按钮时,将调用以下代码来调用弹出窗体并开始复制过程.第二种形式的.show()在构造函数中调用.弹出窗体的.start()函数进行实际的复制.

我遇到的问题是表单出现了,但是只部分显示了它的元素……也就是说,确定"和取消"按钮没有显示,它们的位置只是灰色空间.在副本末尾,它们终于出现了.为什么是这样?好像表单开始显示,停止开始进行复制,然后完成显示一样.

我不明白的是,我先在容器中调用了.show(),然后又调用了.start()...为什么表单不首先显示所有内容并进行复制?另外值得注意的是,我尝试在单独的线程中执行.show()毫无用处.请帮忙.

I''m writing a simple app to copy files from one location to another. It consists of only two forms:

The main form where the user selects source and destination and hits a button to begin the copy process

A pop-up form (frmProgress) with a progressbar, ok, and cancel button.

When the user hits the copy button on the main form the following code is invoked to call the pop-up form and begin the copy process. The .show() for the second form is invoked in the constructor. The .start() function of the pop-up form does the actual copying.

The problem I''m having is that the form comes up but only partially displays its elements... that is, the okay and cancel buttons are not showing and in their place is just grey space. At the end of the copy they finally appear. Why is this? It''s as if the form starts to display, stops to start doing the copying, and then finishes displaying.

What I don''t get is I called the .show() first, in the contstuctor, and then I called the .start()... why does the form not display everything first and do the copying? Also worth noting, is that I tried to do the .show() in a seperate thread by to no avail. Please help.

frmprog = new frmProgress(sourceControl.txtDestinationPath.Text, destinations);
//frmprog.Visible = true;
frmprog.start();

推荐答案

您的表单执行工作时,它会阻塞UI线程,这就是为什么您的表单无法绘制的原因直到工作完成为止.在MSDN上查找BackgroundWorker ,您将看到如何将复制任务放入工作线程并释放UI线程.
When your form''s doing work, it blocks the UI thread and this is why your form does not paint properly until the work''s done. Look up BackgroundWorker on MSDN and you''ll see how you can put the copy task into the worker thread and free up your UI thread.


这篇关于控件通过进度条显示在表单的后面.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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