How can I allow selecting and copying of text from MessageBox in WPF?
Here's a simple trick that you may not be aware of. To copy text from message box in Windows 10, simply press the Ctrl+C hotkey to copy the message box text and you are done! Then, do not click the OK button, press the CTRL + C hotkey instead. The contents of the message box will be copied to the clipboard.
MessageBox with Default Button By default, the first button is the default button. The MessageBoxDefaultButton enumeration is used for this purpose and it has the following three values. The following code snippet creates a MessageBox with a title, buttons, and an icon and sets the second button as a default button.
If you don't need selecting text as a requirement, just use System.Windows.Forms.MessageBox. It maps to the system-default one which already allows copying its contents with Ctrl+C.
You can just use Ctrl+C while the message box has focus, but it will give you a lot more text than just the error message.
e.g.
MessageBox.Show("Message", "Message Title", MessageBoxButton.OK);
Would copy and paste as:
--------------------------- Message Title --------------------------- Message --------------------------- OK ---------------------------
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With