{"id":22065612,"url":"https://github.com/karenpayneoregon/task-dialog-csharp","last_synced_at":"2025-06-12T02:33:31.064Z","repository":{"id":51001040,"uuid":"441945237","full_name":"karenpayneoregon/task-dialog-csharp","owner":"karenpayneoregon","description":"Code samples in C# for using TaskDialog","archived":false,"fork":false,"pushed_at":"2024-09-06T09:44:40.000Z","size":670,"stargazers_count":11,"open_issues_count":0,"forks_count":4,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-01T05:34:38.190Z","etag":null,"topics":["csharp-core","csharp-library","taskdialog"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/karenpayneoregon.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-12-26T17:18:25.000Z","updated_at":"2024-11-23T22:05:55.000Z","dependencies_parsed_at":"2023-01-31T03:16:00.100Z","dependency_job_id":null,"html_url":"https://github.com/karenpayneoregon/task-dialog-csharp","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/karenpayneoregon%2Ftask-dialog-csharp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/karenpayneoregon%2Ftask-dialog-csharp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/karenpayneoregon%2Ftask-dialog-csharp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/karenpayneoregon%2Ftask-dialog-csharp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/karenpayneoregon","download_url":"https://codeload.github.com/karenpayneoregon/task-dialog-csharp/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253852035,"owners_count":21973841,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["csharp-core","csharp-library","taskdialog"],"created_at":"2024-11-30T19:20:42.564Z","updated_at":"2025-05-13T01:24:19.062Z","avatar_url":"https://github.com/karenpayneoregon.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# .NET Core TaskDialog\n\nWhen an application requires a message to be display or to ask a user questions the common method is to use a [MessageBox](https://docs.microsoft.com/en-us/dotnet/api/system.windows.forms.messagebox?view=windowsdesktop-6.0).\n\n:heavy_check_mark: See [article](https://dev.to/karenpayneoregon/net-core-taskdialog-2o4l)\n\n\n\u003e **Note**\n\u003e With .NET Core 5 and higher there is TaskDialog. All code provided started out as .NET Core 5 and has been updated to use .NET Core 7. \n\nA standard `message box` with its many `overloads` for `Show` method is fine for simply displaying and asking for input (without a input/textbox) while the TaskDialog provides more flexibilities. With these flexibilities comes more code which can be placed into a separate class in a project or better, place code into a separate class project. To use the class project, add a reference to a project or create a NuGet local package and install the package in any project.\n\nBelow find common examples for using a TaskDialog in a Windows Form and WPF projects. And note that there are many more methods to explore in the class project WindowsFormsLibrary.\n\n![img](assets/Example12.png)\n\n\u003c/br\u003e\n\n![img](assets/Example13.png)\n\n\u003c/br\u003e\n\n![img](assets/Example15.png)\n\n:bulb: There are 25 plus examples to learn `TaskDialog` from, take time to traverse the code rather than simply running the code samples to get a grasp of what is possible.\n\n## Front end projects\n\nThere are two frontend projects, one Windows Forms and one WPF. The Windows Forms project has more code samples but the WPF project is capable of the same code as found in the Windows Forms project. Why? Generally speaking there are more developers using Windows Forms than WPF.\n\nA third project, AutoCloseNotTaskDialog is a clean way to have a auto closing MessageBox prior to .NET Core 5. This project has not been updated to .NET Core 7.\n\n## How to use\n\nBest way to use the code is to take the class project WindowsFormsLibrary, place it in a Visual Studio solution then build the solution.\n\nFor ease of use, redirect the build output to a library folder e.g. C:\\DotNet\\Libraries then when needed in a frontend project, add a reference to the dll. Alternate is to create a local NuGet package, add the local NuGet folder to NuGet package manager under Visual Studio and when needed install the package to a project.\n\nHere the author (Karen) uses C:\\Dotnetland\\NuGet for local packages\n\n![img](assets/Example14.png)\n\n\n### Basic example to display a message\n\nThe following will display a message center screen.\n\n```csharp\nMessageBox.Show(\"Something went wrong!!!\");\n```\n\n![img](assets/Example1.png)\n\nThere is an overload to center a MessageBox on a form which looks simple\n\n```csharp\nShow(IWin32Window, String)\n```\n\nBut try and implement it is not so easy, we need to create a method to transform a form handle using\n\n```csharp\npublic class Win32Window : IWin32Window\n{\n    readonly IntPtr handle;\n    public Win32Window(IWin32Window window)\n    {\n        handle = window.Handle;\n    }\n    IntPtr IWin32Window.Handle =\u003e handle;\n}\n```\n\nWhich is passed as the first parameter to the Show method.\n\nUsing `TaskDialog` use the following code.\n\n```csharp\n/// \u003csummary\u003e\n/// displays a message with option to assign button text\n/// \u003c/summary\u003e\n/// \u003cparam name=\"owner\"\u003econtrol or form\u003c/param\u003e\n/// \u003cparam name=\"heading\"\u003e\u003c/param\u003e\n/// \u003cparam name=\"buttonText\"\u003e\u003c/param\u003e\npublic static void Information(Control owner, string heading, string buttonText = \"Ok\")\n{\n\n    TaskDialogButton okayButton = new (buttonText);\n\n    TaskDialogPage page = new ()\n    {\n        Caption = \"Information\",\n        SizeToContent = true,\n        Heading = heading,\n        Icon = TaskDialogIcon.Warning,\n        Buttons = new TaskDialogButtonCollection() { okayButton }\n    };\n    \n    TaskDialog.ShowDialog(owner, page);\n\n}\n```\n\n**Usage**\n\n```csharp\nDialogs.Information(this,\"Something went wrong\");\n```\n\n![img](assets/Example2.png)\n\nLet's use our own Icon from project resources (available in code)\n\n```csharp\n/// \u003csummary\u003e\n/// displays a message with option to assign button text\n/// \u003c/summary\u003e\n/// \u003cparam name=\"owner\"\u003econtrol or form\u003c/param\u003e\n/// \u003cparam name=\"heading\"\u003e\u003c/param\u003e\n/// \u003cparam name=\"buttonText\"\u003e\u003c/param\u003e\npublic static void Information(Control owner, string heading, string buttonText = \"Ok\")\n{\n    TaskDialogButton okayButton = new (buttonText);\n\n    TaskDialogPage page = new ()\n    {\n        Caption = \"Information\",\n        SizeToContent = true,\n        Heading = heading,\n        Icon = new TaskDialogIcon(Properties.Resources.Explaination),\n        Buttons = new TaskDialogButtonCollection() { okayButton }\n    };\n    \n    TaskDialog.ShowDialog(owner, page);\n\n}\n```\n\n![img](assets/Example3.png)\n\nUsing the buttonText to override the default text of OK.\n\n```csharp\nDialogs.Information(this,\"Something went wrong\", \"Oooops\");\n```\n\n\n![img](assets/Example4.png)\n\n:bulb: Dialogs can be removed by using a static import using statement\n\n```csharp\nusing static WindowsFormsLibrary.Classes.Dialogs;\n```\n\n### Basic example to ask a question\n\nWith MessageBox, a question is done as shown below\n\n```csharp\nif (MessageBox.Show(\"Would you like a cup of Coffee?\", \"Question\", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)\n{\n    ...\n}\nelse\n{\n    ...\n}\n```\n\nLike in the first example to show a message, the handle may be passed to center the dialog on the form.\n\nA cleaner method is to place the following code in a class\n\n```csharp\n        public static bool Question(string text) =\u003e\n            (MessageBox.Show(text, \"Question\", \n                MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.Yes);\n```\n\nUsage\n\n```csharp\nif (Dialogs.Question(\"Would you like a cup of Coffee?\"))\n{\n    ...\n}\nelse\n{\n    ...\n}\n```\n\n![img](assets/Example5.png)\n\nWith TaskDialog we can have several overloads\n\nLet's show an example using WPF\n\n![img](assets/Example6.png)\n\n\n\n```csharp\n/// \u003csummary\u003e\n/// Dialog to ask a question\n/// \u003c/summary\u003e\n/// \u003cparam name=\"caption\"\u003etext for dialog caption\u003c/param\u003e\n/// \u003cparam name=\"heading\"\u003etext for dialog heading\u003c/param\u003e\n/// \u003cparam name=\"yesText\"\u003etext for yes button\u003c/param\u003e\n/// \u003cparam name=\"noText\"\u003etext for no button\u003c/param\u003e\n/// \u003cparam name=\"defaultButton\"\u003especifies the default button for this dialog\u003c/param\u003e\n/// \u003creturns\u003etrue for yes button, false for no button\u003c/returns\u003e\npublic static bool Question(string caption, string heading, string yesText, string noText, DialogResult defaultButton)\n{\n\nTaskDialogButton yesButton = new (yesText) { Tag = DialogResult.Yes };\nTaskDialogButton noButton = new (noText) { Tag = DialogResult.No };\n\nTaskDialogButtonCollection buttons = new ();\n\nif (defaultButton == DialogResult.Yes)\n{\n    buttons.Add(yesButton);\n    buttons.Add(noButton);\n}\nelse\n{\n    buttons.Add(noButton);\n    buttons.Add(yesButton);\n}\n\nTaskDialogPage page = new ()\n{\n    Caption = caption,\n    SizeToContent = true,\n    Heading = heading,\n    Icon = TaskDialogIcon.Information,\n    Buttons = buttons\n};\n\n\nTaskDialogButton result = TaskDialog.ShowDialog(page);\n\nreturn (DialogResult)result.Tag == DialogResult.Yes;\n\n}\n\n/// \u003csummary\u003e\n/// Dialog to ask a question\n/// \u003c/summary\u003e\n/// \u003cparam name=\"owner\"\u003econtrol or form\u003c/param\u003e\n/// \u003cparam name=\"caption\"\u003etext for dialog caption\u003c/param\u003e\n/// \u003cparam name=\"heading\"\u003etext for dialog heading\u003c/param\u003e\n/// \u003cparam name=\"yesText\"\u003etext for yes button\u003c/param\u003e\n/// \u003cparam name=\"noText\"\u003etext for no button\u003c/param\u003e\n/// \u003cparam name=\"defaultButton\"\u003especifies the default button for this dialog\u003c/param\u003e\n/// \u003creturns\u003etrue for yes button, false for no button\u003c/returns\u003e\npublic static bool Question(Form owner, string caption, string heading, string yesText, string noText, DialogResult defaultButton)\n{\n\nTaskDialogButton yesButton = new (yesText) { Tag = DialogResult.Yes };\nTaskDialogButton noButton = new (noText) { Tag = DialogResult.No };\n\nvar buttons = new TaskDialogButtonCollection();\n\nif (defaultButton == DialogResult.Yes)\n{\n    buttons.Add(yesButton);\n    buttons.Add(noButton);\n}\nelse\n{\n    buttons.Add(noButton);\n    buttons.Add(yesButton);\n}\n\n\nTaskDialogPage page = new ()\n{\n    Caption = caption,\n    SizeToContent = true,\n    Heading = heading,\n    Icon = TaskDialogIcon.Information,\n    Buttons = buttons\n};\n\nvar result = TaskDialog.ShowDialog(owner, page);\n\nreturn (DialogResult)result.Tag == DialogResult.Yes;\n\n}\n/// \u003csummary\u003e\n/// WPF Dialog to ask a question\n/// \u003c/summary\u003e\n/// \u003cparam name=\"owner\"\u003ewindow\u003c/param\u003e\n/// \u003cparam name=\"caption\"\u003etext for dialog caption\u003c/param\u003e\n/// \u003cparam name=\"heading\"\u003etext for dialog heading\u003c/param\u003e\n/// \u003cparam name=\"yesText\"\u003etext for yes button\u003c/param\u003e\n/// \u003cparam name=\"noText\"\u003etext for no button\u003c/param\u003e\n/// \u003cparam name=\"defaultButton\"\u003especifies the default button for this dialog\u003c/param\u003e\n/// \u003creturns\u003etrue for yes button, false for no button\u003c/returns\u003e\npublic static bool Question(IntPtr owner, string caption, string heading, string yesText, string noText, DialogResult defaultButton = DialogResult.No)\n{\n\nTaskDialogButton yesButton = new(yesText) { Tag = DialogResult.Yes };\nTaskDialogButton noButton = new(noText) { Tag = DialogResult.No };\n\nvar buttons = new TaskDialogButtonCollection();\n\nif (defaultButton == DialogResult.Yes)\n{\n    buttons.Add(\"yesButton\");\n    buttons.Add(\"noButton\");\n}\nelse\n{\n    buttons.Add(noButton);\n    buttons.Add(yesButton);\n}\n\nTaskDialogPage page = new()\n{\n    Caption = caption,\n    SizeToContent = true,\n    Heading = heading,\n    Icon = TaskDialogIcon.Information,\n    Buttons = buttons\n};\n\nvar result = TaskDialog.ShowDialog(owner, page, TaskDialogStartupLocation.CenterOwner);\n\nreturn (DialogResult)result.Tag == DialogResult.Yes;\n\n}\n\n/// \u003csummary\u003e\n/// Windows Forms dialog to ask a question\n/// \u003c/summary\u003e\n/// \u003cparam name=\"owner\"\u003e\u003c/param\u003e\n/// \u003cparam name=\"heading\"\u003etext for dialog heading\u003c/param\u003e\n/// \u003cparam name=\"icon\"\u003eIcon to display\u003c/param\u003e\n/// \u003cparam name=\"defaultButton\"\u003eButton to focus\u003c/param\u003e\n/// \u003creturns\u003etrue for yes button, false for no button\u003c/returns\u003e\npublic static bool Question(Control owner, string heading, Icon icon, DialogResult defaultButton = DialogResult.Yes)\n{\n\nTaskDialogButton yesButton = new(\"Yes\") { Tag = DialogResult.Yes };\nTaskDialogButton noButton = new(\"No\") { Tag = DialogResult.No };\n\nvar buttons = new TaskDialogButtonCollection();\n\nif (defaultButton == DialogResult.Yes)\n{\n    buttons.Add(yesButton);\n    buttons.Add(noButton);\n}\nelse\n{\n    buttons.Add(noButton);\n    buttons.Add(yesButton);\n}\n\nTaskDialogPage page = new()\n{\n    Caption = \"Question\",\n    SizeToContent = true,\n    Heading = heading,\n    Icon = new TaskDialogIcon(icon),\n    Buttons = buttons\n};\n\nvar result = TaskDialog.ShowDialog(owner, page);\n\nreturn (DialogResult)result.Tag == DialogResult.Yes;\n\n}\n/// \u003csummary\u003e\n/// Windows Forms dialog to ask a question\n/// \u003c/summary\u003e\n/// \u003cparam name=\"owner\"\u003e\u003c/param\u003e\n/// \u003cparam name=\"heading\"\u003etext for dialog heading\u003c/param\u003e\n/// \u003cparam name=\"defaultButton\"\u003eButton to focus\u003c/param\u003e\n/// \u003creturns\u003etrue for yes button, false for no button\u003c/returns\u003e\npublic static bool Question(Control owner, string heading, DialogResult defaultButton = DialogResult.Yes)\n{\n\nTaskDialogButton yesButton = new(\"Yes\") { Tag = DialogResult.Yes };\nTaskDialogButton noButton = new(\"No\") { Tag = DialogResult.No };\n\nTaskDialogButtonCollection buttons = new TaskDialogButtonCollection();\n\nif (defaultButton == DialogResult.Yes)\n{\n    buttons.Add(yesButton);\n    buttons.Add(noButton);\n}\nelse\n{\n    buttons.Add(noButton);\n    buttons.Add(yesButton);\n}\n\nTaskDialogPage page = new()\n{\n    Caption = \"Question\",\n    SizeToContent = true,\n    Heading = heading,\n    Icon = new TaskDialogIcon(Properties.Resources.QuestionBlue),\n    Buttons = buttons, \n    AllowCancel = true\n};\n\nvar result = TaskDialog.ShowDialog(owner, page);\nreturn result.Tag is not null \u0026\u0026 (DialogResult)result.Tag == DialogResult.Yes;\n}\n\n/// \u003csummary\u003e\n/// Windows Forms dialog to ask a question\n/// \u003c/summary\u003e\n/// \u003cparam name=\"owner\"\u003e\u003c/param\u003e\n/// \u003cparam name=\"heading\"\u003etext for dialog heading\u003c/param\u003e\n/// \u003cparam name=\"yesAction\"\u003e\u003c/param\u003e\n/// \u003creturns\u003etrue for yes button, false for no button\u003c/returns\u003e\npublic static void Question(Control owner, string heading, Action yesAction, Action noAction)\n{\n\nTaskDialogButton yesButton = new(\"Yes\") { Tag = DialogResult.Yes };\nTaskDialogButton noButton = new(\"No\") { Tag = DialogResult.No };\n\nvar buttons = new TaskDialogButtonCollection\n{\n    yesButton,\n    noButton\n};\n\n\nTaskDialogPage page = new()\n{\n    Caption = \"Question\",\n    SizeToContent = true,\n    Heading = heading,\n    Icon = new TaskDialogIcon(Properties.Resources.QuestionBlue),\n    Buttons = buttons\n};\n\nvar result = TaskDialog.ShowDialog(owner, page);\n\nif ((DialogResult)result.Tag == DialogResult.Yes)\n{\n    yesAction?.Invoke();\n}\nelse\n{\n    noAction?.Invoke();\n}\n\n}\n/// \u003csummary\u003e\n/// Windows Forms dialog to ask a question\n/// \u003c/summary\u003e\n/// \u003cparam name=\"heading\"\u003etext for dialog heading\u003c/param\u003e\n/// \u003cparam name=\"icon\"\u003eIcon to display\u003c/param\u003e\n/// \u003cparam name=\"defaultButton\"\u003eButton to focus\u003c/param\u003e\n/// \u003creturns\u003etrue for yes button, false for no button\u003c/returns\u003e\npublic static bool Question(string heading, Icon icon, DialogResult defaultButton = DialogResult.Yes)\n{\n\nTaskDialogButton yesButton = new(\"Yes\") { Tag = DialogResult.Yes };\nTaskDialogButton noButton = new(\"No\") { Tag = DialogResult.No };\n\nvar buttons = new TaskDialogButtonCollection();\n\nif (defaultButton == DialogResult.Yes)\n{\n    buttons.Add(yesButton);\n    buttons.Add(noButton);\n}\nelse\n{\n    buttons.Add(noButton);\n    buttons.Add(yesButton);\n}\n\nTaskDialogPage page = new()\n{\n    Caption = \"Question\",\n    SizeToContent = true,\n    Heading = heading,\n    Icon = new TaskDialogIcon(icon),\n    Buttons = buttons\n};\n\nvar result = TaskDialog.ShowDialog(page);\n\nreturn (DialogResult)result.Tag == DialogResult.Yes;\n\n}\n/// \u003csummary\u003e\n/// WPF dialog to ask a question\n/// \u003c/summary\u003e\n/// \u003cparam name=\"owner\"\u003e\u003c/param\u003e\n/// \u003cparam name=\"heading\"\u003etext for dialog heading\u003c/param\u003e\n/// \u003cparam name=\"icon\"\u003eIcon to display\u003c/param\u003e\n/// \u003cparam name=\"defaultButton\"\u003eButton to focus\u003c/param\u003e\n/// \u003creturns\u003etrue for yes button, false for no button\u003c/returns\u003e\npublic static bool Question(IntPtr owner, string heading, Icon icon, DialogResult defaultButton = DialogResult.Yes)\n{\n\nTaskDialogButton yesButton = new(\"Yes\") { Tag = DialogResult.Yes };\nTaskDialogButton noButton = new(\"No\") { Tag = DialogResult.No };\n\nvar buttons = new TaskDialogButtonCollection();\n\nif (defaultButton == DialogResult.Yes)\n{\n    buttons.Add(yesButton);\n    buttons.Add(noButton);\n}\nelse\n{\n    buttons.Add(noButton);\n    buttons.Add(yesButton);\n}\n\nTaskDialogPage page = new()\n{\n    Caption = \"Question\",\n    SizeToContent = true,\n    Heading = heading,\n    Icon = new TaskDialogIcon(icon),\n    Buttons = buttons\n};\n\n\n\nvar result = TaskDialog.ShowDialog(owner, page, TaskDialogStartupLocation.CenterOwner);\n\nreturn (DialogResult)result.Tag == DialogResult.Yes;\n\n}\n```\n\n**Note** we can also use `Actions` passed to a Question.\n\n```csharp\nDialogs.Question(this, \"Ask something\", YesMethod, NoMethod);\n```\n\nSetup events for the above that are in scope to the method used above.\n\n```csharp\npublic void YesMethod()\n{\n    Debug.WriteLine(nameof(YesMethod));\n}\npublic void NoMethod()\n{\n    Debug.WriteLine(nameof(NoMethod));\n}\n```\n\n\n### Basic example auto-close dialog\n\nWith TaskDialog we can create a method to auto-close as shown below where the last parameter is how many seconds to wait before closing using a customer NumericUpDown control.\n\n![img](assets/Example7.png)\n\n```csharp\nDialogs.AutoCloseDialog(this,Properties.Resources.Timer_16x,SecondsUpDown.AsInteger);\n```\n\nMethod for above\n\n```csharp\n/// \u003csummary\u003e\n/// Auto close dialog by specified seconds, if timed out\n/// invoke continue button.\n/// \u003c/summary\u003e\n/// \u003cparam name=\"owner\"\u003econtrol or form\u003c/param\u003e\n/// \u003cparam name=\"Icon\"\u003eicon to present\u003c/param\u003e\n/// \u003cparam name=\"seconds\"\u003eseconds to timeout\u003c/param\u003e\n/// \u003cparam name=\"okText\"\u003etext for continue button\u003c/param\u003e\n/// \u003cparam name=\"cancelText\"\u003etext for cancel button\u003c/param\u003e\npublic static void AutoCloseDialog(Control owner, Icon Icon, int seconds, string okText = \"OK\", string cancelText = \"Cancel\")\n{\n\n    var remaining = seconds * 10;\n\n    TaskDialogButton continueButton = new(okText);\n    TaskDialogButton cancelButton = new(cancelText);\n\n    TaskDialogPage page = new()\n    {\n        Heading = \"Continuing with next process...\",\n        Text = \"Some text\",\n        Icon = new TaskDialogIcon(Icon),\n        Buttons = new TaskDialogButtonCollection() { continueButton, cancelButton },\n        Caption = \"Auto-close\"\n    };\n\n    using Timer timer = new()\n    {\n        Enabled = true,\n        Interval = 100\n    };\n\n    timer.Tick += (_, _) =\u003e\n    {\n        remaining -= 1;\n\n        if (remaining != 0) return;\n        timer.Enabled = false;\n        if (continueButton.BoundPage is not null)\n        {\n            continueButton.PerformClick();\n        }\n    };\n\n    TaskDialogButton result = TaskDialog.ShowDialog(owner, page);\n\n    ContinueOperation?.Invoke(result == continueButton);\n\n}\n```\n\n### Do not show again example\n\nDisplaying a message box with an option to now show again as shown below is not possible with a MessageBox.\n\n![img](assets/Example8.png)\n\nFirs thing which is needed is a place to remember do not show again settings. Here a json file is used.\n\n```json\n{\n  \"ShowAgain\": true,\n  \"Heading\": \"Are you sure you want to stop?\",\n  \"Text\": \"Stopping the operation might leave your database in a corrupted state.\",\n  \"Caption\": \"Confirmation\",\n  \"VerificationText\": \"Do not show again\"\n}\n```\n\nUsing the following class to provide dialog settings where `ShowAgain` is set from the result of the following method.\n\n```csharp\n/// \u003csummary\u003e\n/// Display a dialog with option to not display again where thier choice\n/// is stored in appsettings.json\n/// \u003c/summary\u003e\n/// \u003cparam name=\"sender\"\u003e\u003c/param\u003e\n/// \u003cparam name=\"e\"\u003e\u003c/param\u003e\nprivate void DoNotShowAgainButton_Click(object sender, RoutedEventArgs e)\n{\n    var settings = SettingOperations.GetSetting;\n\n    if (!settings.ShowAgain) return;\n    ShowAgainOptions options = new ShowAgainOptions\n    {\n        Heading = settings.Heading,\n        Text = settings.Text,\n        Caption = settings.Caption,\n        Icon = _DatabaseIcon,\n        VerificationText = settings.VerificationText,\n        IntPtr = _intPtr\n    };\n\n    (NoShowResult DialogResult, bool ShowAgain) result = Dialogs.DoNotShowAgain(options);\n    ShowAgainCheckBox.IsChecked = result.ShowAgain;\n\n}\n```\n\nUsage shown for WPF (a Windows Form version is also available)\n\n```csharp\nprivate void DoNotShowAgainButton_Click(object sender, RoutedEventArgs e)\n{\n    var settings = SettingOperations.GetSetting;\n\n    if (!settings.ShowAgain) return;\n    ShowAgainOptions options = new ShowAgainOptions\n    {\n        Heading = settings.Heading,\n        Text = settings.Text,\n        Caption = settings.Caption,\n        Icon = _DatabaseIcon,\n        VerificationText = settings.VerificationText,\n        IntPtr = _intPtr\n    };\n\n    (NoShowResult DialogResult, bool ShowAgain) result = Dialogs.DoNotShowAgain(options);\n    ShowAgainCheckBox.IsChecked = result.ShowAgain;\n\n}\n```\n\n### Link buttons\n\nThese are really nice how we can setup buttons and in this case open a web page.\n\n![img](assets/Example9.png)\n\n```csharp\n/// \u003csummary\u003e\n/// Example for opening a web page for windows forms\n/// \u003c/summary\u003e\n/// \u003cparam name=\"owner\"\u003econtrol or form\u003c/param\u003e\npublic static void OpenLink(Control owner)\n{\n    TaskDialogCommandLinkButton continueButton = new(\"\u0026Quit\", \"Return to caller\");\n    TaskDialogCommandLinkButton linkButton = new(\"\u0026Microsoft docs\", \"Open in default browser\");\n\n    linkButton.SetAddress(\"https://docs.microsoft.com/en-us/documentation/\");\n\n    linkButton.Click += LinkButtonClick;\n\n    TaskDialogPage page = new()\n    {\n        Caption = \"Question\",\n        Heading = \"Open in browser\",\n        AllowCancel = true,\n        Footnote = new TaskDialogFootnote() { Text = $\"Copyright {Now:yyyy}: Some company\" },\n        Buttons = { linkButton, continueButton }, \n        Icon = TaskDialogIcon.Information\n    };\n\n    TaskDialog.ShowDialog(owner,page);\n\n}\n```\n### With a progress bar\n\n![img](assets/Example10.png)\n\n```csharp\npublic static void AutoClosingTaskDialog(Icon Icon)\n{\n\n    const string textFormat = \"Closing in {0} seconds...\";\n    var remainingTenthSeconds = 30;\n\n    TaskDialogButton continueButton = new (\"Just do it\");\n    TaskDialogButton cancelButton = TaskDialogButton.Cancel;\n    \n    TaskDialogPage page = new ()\n    {\n        Heading = \"Continuing with next process...\",\n        Text = string.Format(textFormat, (remainingTenthSeconds + 9) / 10),\n        Icon = new TaskDialogIcon(Icon),\n        ProgressBar = new TaskDialogProgressBar() { State = TaskDialogProgressBarState.Paused },\n        Buttons = new TaskDialogButtonCollection() { continueButton, cancelButton }, \n        Caption = \"Auto-close\"\n    };\n\n    using Timer timer = new ()\n    {\n        Enabled = true,\n        Interval = 100\n    };\n\n    timer.Tick += (_, _) =\u003e\n    {\n        remainingTenthSeconds -= 1;\n\n        if (remainingTenthSeconds \u003e 0)\n        {\n            page.Text = string.Format(textFormat, (remainingTenthSeconds + 9) / 10);\n            page.ProgressBar.Value = 100 - remainingTenthSeconds * 2;\n        }\n        else\n        {\n            timer.Enabled = false;\n\n            if (continueButton.BoundPage is not null)\n            {\n                continueButton.PerformClick();\n            }\n            \n        }\n    };\n\n    TaskDialogButton result = TaskDialog.ShowDialog(page);\n\n    ContinueOperation?.Invoke(result == continueButton);\n\n}\n```\n\n### Implement with Radio buttons\n\nIn the code sample Radio buttons are used along with showing how to handle radio button and link button events.\n\n![img](assets/Example11.png)\n\n\nExample using events\n\n![img](assets/Example15.png)\n\nFirst setup an event for allowing the caller to know the selection.\n\n```csharp\npublic delegate void OnCheck(TaskDialogRadioButton radioButton);\npublic static event OnCheck VisualStudioChecked;\n```\n\nFor the method to display a TaskDialog with, in this case three [TaskDialogRadioButton](https://docs.microsoft.com/en-us/dotnet/api/system.windows.forms.taskdialogradiobutton?view=windowsdesktop-6.0).\n\n- Create selection buttons, one for okay and one for cancel\n- Setup the TaskDialogPage with a Icon from project resources which will \n  - Not beep on Shown\n  - Provides a distinct image to go along with the question\n- Setup each radio button's tag with an enum, each for a different version of Visual Studio\n- Subscribe to CheckedChanged for each TaskDialogRadioButton which the calling form listens\n- Get the results to return in a named value tuple.\n\nenum for bullet 3\n\n```csharp\npublic enum VisualStudioVersion\n{\n    V2017,\n    V2019,\n    V2022,\n    None\n}\n```\n\nExtension method for obtaining the selected radio button\n\n```csharp\npublic static VisualStudioVersion Version(this TaskDialogRadioButton sender) =\u003e \n   sender is null ? VisualStudioVersion.None : (VisualStudioVersion)sender.Tag;\n```\n\n---\n\n\n**Microsoft docs** [TaskDialog](https://docs.microsoft.com/en-us/dotnet/api/system.windows.forms.taskdialog?view=windowsdesktop-6.0)\n\n# WindowsFormsLibrary\n\nThis class project contains code samples ready to use for TaskDialogs for Windows Forms and WPF.\n\n![img](assets/DialogsMethods.png)\n\n\nFor pre .NET Core, [AutoClosingMessageBox](https://www.nuget.org/packages/AutoClosingMessageBox/) for auto-closing message boxes.\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkarenpayneoregon%2Ftask-dialog-csharp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkarenpayneoregon%2Ftask-dialog-csharp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkarenpayneoregon%2Ftask-dialog-csharp/lists"}