Why does the ButtonDownFcn callback not execute when I click on a uicontrol object with the left mouse button in MATLAB 7.0.4 (R14SP2)?

15 views (last 30 days)
I have a GUI containing a uicontrol object such as an edit box. Associated with this uicontrol is a ButtonDownFcn callback.
The callback gets executed when I right-click with my mouse on the Edit Text. But when I click on it with the left mouse button, the callback does not get executed unless I click exactly on the border of the control.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 27 Jun 2009
This is intended behavior for uicontrol objects in MATLAB 7.0.4 (R14SP2). If the uicontrol's "Enable" property is set to "on", the ButtonDownFcn callback executes when you click the right or left mouse button in a 5-pixel border around the uicontrol or when you click the right mouse button on the control itself. If the uicontrol's "Enable" property is set to "inactive" or "off", the ButtonDownFcn executes when you click the right or left mouse button in the 5-pixel border or on the control itself.
This is useful for implementing actions to interactively modify control object properties, such as size and position, when they are clicked on (using SELECTMOVERESIZE, for example).
To enable triggering the ButtonDownFcn when the control is clicked with the left mouse button, set the UICONTROL's "Enable" property to "Inactive" or "Off". This can be done through the Property Inspector in GUIDE (double-clicking on the object in the layout editor) or programmatically with the handle to the uicontrol "hObject" as follows:
set(hObject, 'Enable', 'Inactive');
If, in addition, you would like to use the uicontrol (for example, edit the text in an edit box) and call its Callback function, you will need to toggle the "Enable" state of the object in the ButtonDownFcn and Callback functions. Setting the "Enable" property to "On" in the ButtonDownFcn will allow you to use the control. Then, setting the "Enable" property to "Inactive" in the Callback function will allow you to subsequently click on it and call the ButtonDownFcn. This is demonstrated in the attached GUI. You may execute it by saving both the M- and FIG files to a directory on the MATLAB path and then issuing the following command at the MATLAB prompt
uicontrol_example
For more information on the uicontrol properties, please consult the documentation by executing the following at the MATLAB prompt:
doc uicontrol_props

More Answers (0)

Categories

Find more on Migrate GUIDE Apps in Help Center and File Exchange

Products


Release

R14SP2

Community Treasure Hunt

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

Start Hunting!