4

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)

Abraham
  • 1,209
  • 2
  • 14
  • 22

2 Answers2

4

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();
Community
  • 1
  • 1
phadaphunk
  • 12,785
  • 15
  • 73
  • 107
  • I want it to be easier for my users to copy text. I'll take a look at that, but I'm mainly interested if I can add a button to copy the text – Abraham Apr 12 '13 at 20:29
1

It sounds like maybe you are looking for the Clipboard class.

Clipboard.SetText(variableWithValue);

There is also another answer here about manipulating the contents of a Message Box.

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

Community
  • 1
  • 1
AJ Henderson
  • 1,120
  • 1
  • 12
  • 32