-2

Actually I need a messageBox with custom buttons, and I don't want to use another form or messageBoxManager as a messageBox. I thought maybe a TaskDialog help me but i don't know how to use it.

  • If you want to use something and don't know how, the next step is to learn. Once you think you've learned how, try to do it. If what you do doesn't work, then you have a question to ask us. – John Aug 11 '22 at 08:16
  • That said, why don't you want to just use a form of your own creation? I suspect that your reasoning is not good on that one. – John Aug 11 '22 at 08:17

1 Answers1

1

Check out Microsoft TechNet article with source .NET Core 5 TaskDialog (C#)

enter image description here

Ask a question

public static bool Question(Form owner, string caption, string heading, string yesText, string noText, DialogResult defaultButton)
{

    TaskDialogButton yesButton = new (yesText) { Tag = DialogResult.Yes };
    TaskDialogButton noButton = new (noText) { Tag = DialogResult.No };

    var buttons = new TaskDialogButtonCollection();

    if (defaultButton == DialogResult.Yes)
    {
        buttons.Add(yesButton);
        buttons.Add(noButton);
    }
    else
    {
        buttons.Add(noButton);
        buttons.Add(yesButton);
    }


    TaskDialogPage page = new ()
    {
        Caption = caption,
        SizeToContent = true,
        Heading = heading,
        Icon = TaskDialogIcon.Information,
        Buttons = buttons
    };

    var result = TaskDialog.ShowDialog(owner, page);

    return (DialogResult)result.Tag == DialogResult.Yes;

}

Show information

public static void Information(IntPtr owner, string heading, string buttonText = "Ok")
{

    TaskDialogButton okayButton = new(buttonText);

    TaskDialogPage page = new()
    {
        Caption = "Information",
        SizeToContent = true,
        Heading = heading,
        //Icon = TaskDialogIcon.Information, -- will invoke a beep
        Buttons = new TaskDialogButtonCollection() { okayButton }
    };
    
    TaskDialog.ShowDialog(owner, page);

}
Karen Payne
  • 4,341
  • 2
  • 14
  • 31