0

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.

skaffman
  • 398,947
  • 96
  • 818
  • 769

1 Answers1

0

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" };
luviktor
  • 2,240
  • 2
  • 22
  • 23