Add button to copy text to MessageBox

I have a program that contains a list of names and a button that displays a random name in a MessageBox. Is there a way to add the Copy button next to OK in the MessageBox so that when I click it copies the name and then closes?

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

Thanks.

edit: My users will not understand Ctrl + C, Highlight and Right Click> Copy is what I am looking for (if the copy button is not possible)

+4
source share
2 answers

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

I googled your headline and found this .

Or, if you really need a button with a copy, you can create your own MessageBox with a new window shape, and then do what you want with the buttons. Open it to save the MessageBox :

 var myMessageBox = new CustomMessageBox(); myMessageBox.ShowDialog(); 
+3
source

It looks like you are looking for the Clipboard class.

 Clipboard.SetText(variableWithValue); 

There is also another answer here on how to manipulate the contents of the message box.

It may also be easier to simply create a modal dialog that emulates a MessageBox without actually using the MessageBox class.

+1
source

All Articles