Search code examples
c#winformsmessagebox

Add button to copy text in MessageBox


I have a program that contains a list of names, and a button that displays a random name in a MessageBox. Is there any way I can add a button "Copy" next to the OK to the MessageBox, that when clicked copies the name and then closes?

If the above isn't possible, is there a way to enable copying the text in a MessageBox?

Thank you.

edit: My users won't understand Ctrl+C, Highlight and Right Click > Copy is what I'm looking for (if a Copy button isn't possible)


Solution

  • If a user presses Ctrl-C while the MessageBox has focus, the message, the MessageBox caption and the MessageBoxButtons labels are copied to the clipboard.

    I googled your title and found this..

    Or if you really need a button that says copy you can create your own MessageBox with a new windows form and then do what you want with the buttons. Open it like this to keep the MessageBox feel :

    var myMessageBox = new CustomMessageBox();
    myMessageBox.ShowDialog();