I have a code sample here which uses the following NuGet package, WindowsAPICodePack-Core which is free. No perfect but close.
Example
using System;
using System.Windows.Forms;
using DialogsSharp.Classes;
namespace DialogsSharp
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void CenterOnFormButton_Click(object sender, EventArgs e)
{
DialogHelpers.CenterOnParent();
}
}
}
Code
using System;
using System.IO;
using System.Windows.Forms;
using Microsoft.WindowsAPICodePack.Dialogs;
namespace DialogsSharp.Classes
{
public static class DialogHelpers
{
public static void CenterOnParent()
{
var yesButton = new TaskDialogButton("CloseTaskDialogButton", "Yes")
{
Default = true
};
var noButton = new TaskDialogButton("ProceedTaskDialogButton", "No");
var dialog = new TaskDialog
{
Caption = "Question",
InstructionText = $"Would you like to continue?",
Icon = TaskDialogStandardIcon.Information,
Cancelable = false,
StartupLocation = TaskDialogStartupLocation.CenterOwner
};
dialog.Controls.Add(yesButton);
dialog.Controls.Add(noButton);
dialog.OwnerWindowHandle = Form.ActiveForm.Handle;
dialog.Opened += (senderObject, ea) =>
{
var taskDialog = senderObject as TaskDialog;
taskDialog.Icon = taskDialog.Icon;
};
yesButton.Click += (e, a) =>
{
Console.WriteLine("Yes");
dialog.Close(TaskDialogResult.Close);
};
noButton.Click += (e, a) =>
{
Console.WriteLine("No");
dialog.Close(TaskDialogResult.Close);
};
dialog.Show();
}
}
}
Edit
Added another option in the same repository, see this library. I still favor the other library as it has more options overall.