简体   繁体   中英

uiwait color button - Matlab

I have this small Matlab code:

uiwait(warndlg('Try 1.  Click OK to continue'));
uiwait(msgbox('Try 2'));

Is it possible to change the color of the OK button to another color (eg, dark gray)?

If you want to change the color of the OK button (and not of the message box), you need to access the Children of that message box first and change the BackgroundColor property. For a dark gray box I'll use the RGB triplet [.2 .2 .2]

Therefore:

hMsg=warndlg('Try 1.  Click OK to continue');

%// Get children
Children = get(hMsg,'Children');

%// The OK button is the 1st
OKButton = Children(1);

set(OKButton,'BackgroundColor',[.2 .2 .2])

uiwait(hMsg) %// Wait for button click; needed if you want code to stop. Thanks Jonas.

Output:

在此处输入图片说明

Of course doing it in one go yields the same result:

set(Children(1),'BackgroundColor',[.2 .2 .2])

To change the color of the warndlg pushbutton you have to first get the handle of the pushbutton.

To get the handle of the pushbutton you need the handle of the warndlg .

To get the handle of the of the warndlg you need to modify your code as follows:

% Create the warning dialog figure and get its handle
h=warndlg('Try 1.  Click OK to continue')
% Find the warning dialog figure pushbutton handle
wh=findobj(h,'style','pushbutton')
% Set the pushbutton background color to "dark gray"
set(wh,'BackgroundColor',[.5 .5 .5])
% Set the pushbutton foreground color to "white"
set(wh,'foregroundColor',[1 1 1])
% Call uiwait for the warning dialog figur
uiwait(h)

Hope this helps.

试试功能集(hMsg,'color','white');

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