Learn about Task Dialogs in C#

This is called Task Dialog and its a part of WindowsAPICodePack, available for download from https://www.nuget.org/packages/WindowsAPICodePack/

What we're going to do in this article is create a Task Dialog with customizable texts and a hyperlink that opens your webpage using Process.

The application will look like this(its a localized Windows 7 by the way).

Localized Windows 7

First of all, create a new Windows Forms application.

Then add these references.

Microsoft.WindowsAPICodePack.dll

which can be found on your extracted archive after you downloaded it.

..\Windows API Code Pack 1.1\Windows API Code Pack 1.1\binaries\Microsoft.WindowsAPICodePack.dll

After that create a TaskDialogCommandLink variable.

TaskDialogCommandLink link = null;

This will help us to access it from another event to open your website.

Now let's keep going.

Create a TaskDialog variable

TaskDialog dia = new TaskDialog();

This is the Dialog Window we wish to create. Here we created it actually

Let's play with its properties by adding more functionality to it.

dia.Cancelable = true;
dia.InstructionText = "Friend Request";
dia.StandardButtons = TaskDialogStandardButtons.Yes | TaskDialogStandardButtons.No;

Cancelable means we can close/cancel the dialog if we want.

InstructionText is the above text inside the dialog. You can give it a general name like Friend Request, Mail Sent, Password Changed, and goes on.

StandardButtons are as you can see, added two of them; Now let's play with CommandLink.

link = new TaskDialogCommandLink("http://www.iersoy.com", "Anonymous just added you as Friend in Facebook!", "Do you accept?");
link.UseElevationIcon = true;
link.Enabled = true;
link.Click += new EventHandler(link_Click);

Here we created a Hyperlink-like structure that uses the Elevation icon and raises an event when clicked on it.

public void link_Click(object sender, EventArgs e)
{
    Process.Start(link.Name);
}

as I told you before we created a commandlink to access an event. That event is this Click event. We access links' names to view them on a web browser. I added my own blog, you can change it later, depending on you.

And let's finalize this application.

dia.Controls.Add(link);
dia.DetailsExpanded = false;
dia.DetailsExpandedText = "Anonymous is a world-wide hacktivist group";
dia.ExpansionMode = TaskDialogExpandedDetailsLocation.ExpandFooter;
dia.Caption = "Information!";
dia.Show();

We're adding this link to Task Dialog so that we can see it. We also assign false to DetailsExpanded to make it look like real Windows 7 Task Dialogs. And we're adding some text regarding information about Anonymous. It displays when you expand the detail icon

And finally, we show it to the user.

Run and you'll see a similar effect shown as the screenshot above

Hope it helps, and you use it in your applications.


Similar Articles