How can I use a drag and drop mechanism to activate a new figure?

조회 수: 1 (최근 30일)
Christian Idzik
Christian Idzik 2016년 8월 4일
편집: Christian Idzik 2016년 8월 4일
I made several GUI's in matlab's guide. One of them is my main menu(containts pushbuttons) in which you can choose a mode. I implemtent a drag and drop mechanism, so you can move the pushbuttons. This works quite well. Now I'm looking to a method to move one button into an area, so it activates the selected mode. That means that the current figure is closed and a new figure would appear. But I don't know how to manage this. Here you can see my drag and drop mechanism
function dragObject(hObject,eventdata)
handles = guidata(gcf);
handles.dragging = hObject;
handles.orPos = get(gcf,'CurrentPoint');
guidata(gcf,handles);
function dropObject(hObject,eventdata)
handles = guidata(gcf);
if ~isempty(handles.dragging)
newPos = get(gcf,'CurrentPoint');
posDiff = newPos - handles.orPos;
set(handles.dragging,'Position',get(handles.dragging,'Position') + [posDiff(1:2) 0 0]);
handles.dragging = [];
guidata(gcf,handles)
end
function moveObject(hObject,eventdata)
handles = guidata(gcf);
if ~isempty(handles.dragging)
newPos = get(gcf,'CurrentPoint');
X= newPos(1,1);
Y=newPos(1,2);
posDiff = newPos - handles.orPos;
handles.orPos = newPos;
set(handles.dragging,'Position',get(handles.dragging,'Position') + [posDiff(1:2) 0 0]);
guidata(gcf,handles)
end

답변 (0개)

카테고리

Help CenterFile Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by