Ciuban - you can try adding a listener (see learn to use events and listeners) to capture the movement of the main GUI so that when its position changes, the other three GUIs position changes as well. For example, suppose that we have two GUIs, the main one and a smaller one that is situated to the right of the main one. The main GUI (named/tagged as Gui1) launches the second GUI (named/tagged Gui2). Within the OpeningFcn of the first we do function Gui1_OpeningFcn(hObject, eventdata, handles, varargin)
handles.output = hObject;
movegui(hObject,'center');
handles.hGui2 = Gui2('Visible','off');
gui1Pos = get(hObject,'Position');
gui2Pos = get(handles.hGui2,'Position');
gui2Pos = [gui1Pos(1)+gui1Pos(3)+5 gui1Pos(2) gui2Pos(3) gui2Pos(4)];
set(handles.hGui2,'Position',gui2Pos,'Visible','on');
handles.gui1Pos = gui1Pos;
handles.gui2Pos = gui2Pos;
handles.gui1PosListener = ...
addlistener(hObject, 'Position', 'PostSet', @(src,event)onGui1PosChange(src,event,hObject));
guidata(hObject, handles);
In the above, we centre the main GUI and then move the other GUI to the right of the first one. The listener is created to respond to changes in position of the main GUI. We define the callback for this listener as
function onGui1PosChange(~,~,hGui)
handles = guidata(hGui);
newGui1Pos = get(hGui,'Position');
gui1PosDelta = handles.gui1Pos - newGui1Pos;
gui1PosDelta(3:4) = 0;
newGui2Pos = handles.gui2Pos - gui1PosDelta;
set(handles.hGui2,'Position',newGui2Pos);
handles.gui1Pos = newGui1Pos;
handles.gui2Pos = newGui2Pos;
guidata(hGui,handles);
Here, we determine the change in position of the first GUI (with respect to its x and y position) and then apply that change to the second GUI.
The attached code uses the above to keep the two GUIs positioned together. From the Command Line, just type
to test this out. Note that the second GUI only moves after the first GUIs position has been finalized (i.e. after you release the mouse button). Try it out and see what happens!
Best Answer