簡體   English   中英

uiwait顏色按鈕-Matlab

[英]uiwait color button - Matlab

我有這個小的Matlab代碼:

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

是否可以將“確定”按鈕的顏色更改為另一種顏色(例如,深灰色)?

如果你想改變OK按鈕(而不是消息框)的顏色,你需要訪問Children :第一,消息框,並更改BackgroundColor屬性。 對於深灰色框,我將使用RGB三元組[.2 .2 .2]

因此:

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.

輸出:

在此處輸入圖片說明

當然,一勞永逸地產生相同的結果:

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

要更改warndlg按鈕的顏色,您必須首先獲取按鈕的handle

要獲得按鈕的handle ,您需要warndlghandle

要獲取warndlg的句柄,您需要按以下方式修改代碼:

% 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)

希望這可以幫助。

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM