显示带有进度栏和自定义按钮的任务对话框时出错

发布于 2024-11-18 21:11:50 字数 1431 浏览 3 评论 0原文

我正在 WindowsAPICodePack 中使用 TaskDialog。当我尝试创建一个没有 TaskDialogProgressBar 和 TaskDialogBu​​tton 的 TaskDialog 时,它会引发以下异常。

System.ComponentModel.Win32Exception 未处理 消息=Win32 调用的参数无效。 来源=Microsoft.WindowsAPICodePack 错误代码=-2147467259 本机错误代码=0 内部异常:System.ArgumentException Message=Value 不在预期范围内。 InnerException:

我想要一个带有进度条的任务对话框来报告状态,但我不希望用户在进度完成之前关闭对话框。所以我使用 TaskDialogBu​​tton 而不是标准关闭按钮。

这是我正在使用的代码。

_taskDialog = new TaskDialog();
_taskDialog.Cancelable = true;
_taskDialog.Caption = "Delete Account";
_taskDialog.InstructionText = "Deleting Account(s)";
_taskDialog.Text = "Please wait until the delete operation completes.";

TaskDialogProgressBar progressbar = new TaskDialogProgressBar();
progressbar.State = TaskDialogProgressBarState.Marquee;
_taskDialog.ProgressBar = progressbar;

TaskDialogButton btnClose = new TaskDialogButton();
btnClose.Click += new EventHandler(OnCloseClick);

_taskDialog.Controls.Add(btnClose);
//_taskDialog.StandardButtons = TaskDialogStandardButtons.Close;

_taskDialog.Icon = TaskDialogStandardIcon.Information;
_taskDialog.OwnerWindowHandle = this.Handle;
_taskDialog.StartupLocation = TaskDialogStartupLocation.CenterOwner;

_taskDialog.Show();

关闭按钮单击的事件处理程序

void OnCloseClick(object sender, EventArgs e)
{
    if (_taskDialog != null)
        _taskDialog.Close();
}

- Matt。

I am using the TaskDialog within WindowsAPICodePack. When I try to create a TaskDialog without just a TaskDialogProgressBar and TaskDialogButton it throws the follow exception.

System.ComponentModel.Win32Exception was unhandled
Message=Invalid arguments to Win32 call.
Source=Microsoft.WindowsAPICodePack
ErrorCode=-2147467259
NativeErrorCode=0
InnerException: System.ArgumentException
Message=Value does not fall within the expected range.
InnerException:

I wanted to have a TaskDialog with the ProgressBar to report the Status, but I dont want the user to close the dialog until the Progress is completed. So I am using a TaskDialogButton instead of the Standard Close button.

Here is the code I am using.

_taskDialog = new TaskDialog();
_taskDialog.Cancelable = true;
_taskDialog.Caption = "Delete Account";
_taskDialog.InstructionText = "Deleting Account(s)";
_taskDialog.Text = "Please wait until the delete operation completes.";

TaskDialogProgressBar progressbar = new TaskDialogProgressBar();
progressbar.State = TaskDialogProgressBarState.Marquee;
_taskDialog.ProgressBar = progressbar;

TaskDialogButton btnClose = new TaskDialogButton();
btnClose.Click += new EventHandler(OnCloseClick);

_taskDialog.Controls.Add(btnClose);
//_taskDialog.StandardButtons = TaskDialogStandardButtons.Close;

_taskDialog.Icon = TaskDialogStandardIcon.Information;
_taskDialog.OwnerWindowHandle = this.Handle;
_taskDialog.StartupLocation = TaskDialogStartupLocation.CenterOwner;

_taskDialog.Show();

EventHandler for Close Button Click

void OnCloseClick(object sender, EventArgs e)
{
    if (_taskDialog != null)
        _taskDialog.Close();
}

-Matt.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夜还是长夜 2024-11-25 21:11:50

尝试两件事:

首先将 taskDialog StandardButtons 属性设置为 None:

_taskDialog.StandardButtons = TaskDialogStandardButtons.None;

其次给 btnClose 命名:

TaskDialogButton btnClose = new TaskDialogButton() { Text = "I'm a button" };

Try two things:

First set the taskDialog StandardButtons property to None:

_taskDialog.StandardButtons = TaskDialogStandardButtons.None;

Second give btnClose a name:

TaskDialogButton btnClose = new TaskDialogButton() { Text = "I'm a button" };
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文