Respond to the left mouse click button in GUI
Show older comments
Hi everyone,
I'm designing a GUI which having several editboxs (allow input), and a figure_axis(explanation figure corresponding to the clicked editbox). I want to it to display my assigned explanation figure when I click (left click) to editboxs. Is there any way to do this?
Thank you so much!
Accepted Answer
More Answers (1)
Geoff Hayes
on 4 Sep 2014
It is possible to capture left-mouse button events around an edit box, but it is a little clumsy, and like Joseph indicated, it won't work if you click within the edit box, just around it.
function captureMouseClick
% create the figure
h = figure;
% create the edit widget
edit1h = uicontrol('Style', 'edit',...
'String', 'enter text here',...
'Position', [20 340 100 50],...
'ButtonDownFcn', @edit1ButtonDown);
% the callback to capture the mouse button down event for the edit widget
function edit1ButtonDown(hObject,~)
% get the last mouse click selection type within the figure
seltype = get(h,'SelectionType');
if strcmpi(seltype,'normal')
fprintf('left mouse button pressed!\n');
elseif strcmpi(seltype,'alt')
fprintf('right mouse button pressed!\n');
elseif strcmpi(seltype,'open')
fprintf('double mouse click!\n');
else
fprintf('other - shift and mouse-click!\n');
end
end
end
Seems only to work if you are within a few pixels outside the border of the edit widget. Try it and see what happens!
Categories
Find more on Interactive Control and Callbacks in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!