简体   繁体   中英

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)

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();

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM