1

我有一个表单,其中有一个按钮复制和其他控件。当用户按下复制按钮时,BackgroundWorker 会执行复制操作。

在复制操作期间,我禁用控件并在完成后重新启用它们。无论如何我可以用更简单的方式做到这一点。就像禁用和启用所有键盘/鼠标输入一样。

PS:如果用户在显示 Hour-Glass 图标时点击,它不应该收集所有这些点击并在 GUI 空闲时触发它们。当 GUI 得到释放时,它应该删除所有累积的点击。

4

3 回答 3

2

Set the form Enable to be false in the start, handle the finish event of the background worker and re-enable the form.

//Lock the form
this.Enabled = false;

Should do it? Excuse me if this isn't what your looking for.

EDIT:

If your looking for a fancier way of doing this you could get an animated .GIF loader from somewhere like here - http://ajaxload.info/ and then create a form with a picture box, no borders with a transparent background. Then use the GIF in there and call ShowDialog at the start and close the dialog at the end of processing, this will display a loader similar to what you see being commonly used and lock the parent form.

于 2012-10-10T08:15:22.370 回答
0

如果您想禁用所有控件,您可以创建新表单,该表单将在后台进程运行时处于活动状态。例如,您可以使用此表单来显示进度。

于 2012-10-10T08:13:31.520 回答
0

该类Form也具有该Enabled属性。

通过禁用Form窗体上的每个控件也将被禁用。这可能是禁用整个窗口的最简单方法。

编辑:

如果您真的只想禁用任何输入而不做任何其他事情,尽管这对用户来说是违反直觉且令人困惑的,那么您可以添加一个新控件,例如在表单顶部没有内容和透明背景的标签.

像这样的东西:

// When starting the operation:
var transparentLabel = new Label();
transparentLabel.Bounds = form.Bounds;
// You may have to set the bacground and border and stuff, I am unsure
form.Children.Add(transparentLabel);
// Change cursor to a hourglass as well?


// When the operation is done
form.Children.Remove(transparentLabel);
// Change cursor back 

这应该确保透明标签获得焦点并禁用对其他控件的输入。

于 2012-10-10T08:15:54.750 回答