Azzera filtri
Azzera filtri

Is there a way to make msgbox copy-paste?

11 visualizzazioni (ultimi 30 giorni)
Andrew
Andrew il 17 Apr 2024
Risposto: Voss il 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?

Risposte (1)

Voss
Voss il 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.

Categorie

Scopri di più su Maintain or Transition figure-Based Apps in Help Center e File Exchange

Tag

Prodotti


Release

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by