One way to set the Selected property via mouse click is to define a ButtonDownFcn for each textbox.
For example this will allow multiple textboxes to be selected at any time (i.e., click to select, click to de-select, independently):
set([foo bar],'ButtonDownFcn',@cb_select_textbox);
function cb_select_textbox(src,evt)
if evt.Button ~= 1 % only allow left-clicks
return
end
if strcmp(src.Selected,'off')
src.Selected = 'on';
else
src.Selected = 'off';
end
end
And this will allow at most one textbox to be selected at any time (i.e., click to select thus deselecting all others, click to de-select):
set([foo bar],'ButtonDownFcn',{@cb_select_textbox,[foo bar]});
function cb_select_textbox(src,evt,textboxes)
if evt.Button ~= 1 % only allow left-clicks
return
end
was_off = strcmp(src.Selected,'off');
set(textboxes,'Selected','off');
if was_off
src.Selected = 'on';
end
end