0
我正在使用GUIDE在matlab中創建GUI。我想在鼠標左鍵關閉時在句柄中創建新字段,當鼠標移動時修改字段並在釋放按鈕時將其刪除。但Windowbuttonmotionfcn回調沒有看到這個新字段。所以,這裏是代碼示例:因爲你只有通過Windowbuttonmotionfcn回調沒有看到句柄中的新字段
set(hObject,'windowbuttonmotionfcn',{@fh_wbmfcn,handles});
的handles
值將永遠是你設置在這一點上一個,:
function fig_OpeningFcn(hObject, eventdata, handles, varargin)
handles.output = hObject;
guidata(hObject, handles);
set(hObject,'windowbuttonmotionfcn',{@fh_wbmfcn,handles});
set(hObject, 'windowbuttondownfcn',{@fh_wbdfcn, handles});
set(hObject, 'windowbuttonupfcn',{@fh_wbufcn, handles});
function fh_wbmfcn(hObject, eventdata, handles)
isfield(handles, 'new_field') % it is always 0, but should be 1 when button is down
function fh_wbdfcn(hObject, eventdata, handles)
handles.new_field=1;
guidata(hObject, handles);
function fh_wbufcn(hObject, eventdata, handles)
if isfield(handles, 'new_field')
handles=rmfield(handles,'new_field');
guidata(hObject, handles);
end