A custom modal dialog as an AppDesigner App

版本 1.0.0 (27.4 KB) 作者: RST
This is sample code for a custom, modal AppDesigner dialog. R2020b onwards
3.0 次下载
更新时间 2024/5/9

查看许可证

A sample custom modal dialog in AppDesigner.
The app is called from an ordinary function, much like uigetfile().
How it works:
1) The modal dialog app
  • sets its main WindowStyle to 'modal'
  • when a button is pressed
  • calls its ValueChangedFcn to pass the dialog result to the caller
  • closes the window
2) A .m-file function 'showModalDialog()'
  • returns a variable 'result' with default value []
  • has an inner function 'valueChanged' that sets 'result' per its one argument
  • when running it
  • creates the ModalDialogApp
  • sets the app's ValueChangedFcn to 'valueChanged'
  • uiwait()s on the dialog's mainFigure
Thus showModalDialog() is blocked until the dialog closes on a button press or window close. The dialog result, if any, is passed via a call to the inner function, thus minimising name pollution.
In this example the dialog result is a scalar double, but the result may be as complex as necessary.
In an app, showModalDialog() could become a private member function; this would, for example, let the app set the position of the dialog.
See MATLAB answer:

引用格式

RST (2024). A custom modal dialog as an AppDesigner App (https://www.mathworks.com/matlabcentral/fileexchange/165686-a-custom-modal-dialog-as-an-appdesigner-app), MATLAB Central File Exchange. 检索时间: .

MATLAB 版本兼容性
创建方式 R2023a
与 R2020b 及更高版本兼容
平台兼容性
Windows macOS Linux

Community Treasure Hunt

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

Start Hunting!
版本 已发布 发行说明
1.0.0