1
我的GUI有兩個編輯框(uicontrol),我想通過左鍵單擊它來更改它們的背景顏色。對於鼠標左鍵單擊,ButtonDownFcn只有在uicontrol Enable屬性設置爲'inactive'或'off'時纔有效,所以我切換屬性以使其工作。uicontrol上的ButtonDownFcn
通過按Tab鍵,我希望我的編輯框將其背景顏色重新初始化爲白色,並更改下一個編輯框的背景顏色。問題是,按下Tab鍵,焦點不會改變,因爲uicontrol啓用屬性是'關閉'或'非活動'。 是否有解決方法?
這是我的代碼到目前爲止。 (EDIT1和EDIT2有相同的代碼)
function edit1_ButtonDownFcn(hObject, eventdata, handles)
set(hObject, 'Enable', 'on', 'BackgroundColor', [0.5,1,0.7]) % change enable and background color properties
uicontrol(hObject) % focus on the current object
function edit1_Callback(hObject, eventdata, handles)
set(hObject, 'Enable', 'inactive', 'BackgroundColor', [1 1 1]) % reinitialize the edit box
謝謝你發現,它完美的作品。只是一個細節:gainFocus函數(hFig)的第一個參數未被使用,因此可以將其刪除。 – oro777