Filter löschen
Filter löschen

Is there a way to make msgbox copy-paste?

11 Ansichten (letzte 30 Tage)
Andrew
Andrew am 17 Apr. 2024
Beantwortet: Voss am 17 Apr. 2024
I want to be able to use the command msgbox and then have users be able to copy-paste the text being displayed from the msgbox. Is there a way to do this?

Antworten (1)

Voss
Voss am 17 Apr. 2024
I don't think there's a way to do that using msgbox, but you can copy text from an 'edit'-style uicontrol, such as is created by inputdlg. For example:
msg = 'here is your message';
inputdlg('','',1,{msg},'on')
The message is already selected when the dialog window opens; hitting ctrl+c when the window appears will copy the message to the clipboard.
You can also copy text from a 'listbox'-style uicontrol, such as is created by listdlg. For example:
msg = 'here is your message';
listdlg('ListString',msg,'ListSize',[200 26],'SelectionMode','single');
The message is already selected when the dialog window opens (avoid double-clicking since that closes the window); hitting ctrl+c when the window appears will copy the message to the clipboard.
If your message has multiple lines, you can increase the listbox height and use 'SelectionMode','multiple' to allow the user to select all the lines at once:
msg = sprintf('here\nis your\nmessage'); % some multi-line message
listdlg('ListString',msg,'ListSize',[200 50],'SelectionMode','multiple');
Besides using inputdlg or listdlg, another option would be to make your own function to display a modal figure or uifigure with a uicontrol (e.g., 'edit'-style or 'listbox'-style) or uitextarea (uifigure only) in it.

Kategorien

Mehr zu Maintain or Transition figure-Based Apps finden Sie in Help Center und File Exchange

Tags

Produkte


Version

R2023a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by