In a data entry GUI program made in GUIDE I want to control the cursor movement from one Edit Text Box to the next: When the user finishes input in an Edit Text Box and press Enter, the cursor should automatically move to the next Edit Text Box without using the mouse. In the following callback function for the Edit Text Box Input_day I want the cursor to move to the box Input_num_var when the user press Enter (the figure with boxes has the name Figure_temp_02):
function Input_day_Callback(hObject, eventdata, handles)
disp(['Input_num_var.Enable 1: ' handles.Input_num_var.Enable]);
handles.Input_num_var.Enable = 'on';
disp(['Input_num_var.Enable 2: ' handles.Input_num_var.Enable]);
disp(['Input_num_var.Selected 1: ' handles.Input_num_var.Selected]);
handles.Input_num_var.Selected = 'on';
disp(['Input_num_var.Selected 2: ' handles.Input_num_var.Selected]);
handles.Figure_temp_02.CurrentObject = handles.Input_num_var;
disp(['Figure_temp_02.CurrentObject.Tag 2: ' handles.Figure_temp_02.CurrentObject.Tag]);
guidata(hObject, handles);
drawnow;
refresh;
When executed the following is shown in the Command Window, but the cursor does not move to Input_num_var box:
Input_num_var.Enable 1: on
Input_num_var.Enable 2: on
Input_num_var.Selected 1: off
Input_num_var.Selected 2: on
Figure_temp_02.CurrentObject.Tag 2: Input_num_var

 Réponse acceptée

Geoff Hayes
Geoff Hayes le 2 Juin 2019

0 votes

Leif - since you are using GUIDE, why not just use the tab key with custom tabbing behaviour to define how focus shifts from one edit control to another? Else you could try using uicontrol.

2 commentaires

Geoff Hayes
Geoff Hayes le 3 Juin 2019
Leif's answer moved here
Thank you for your answer, it was very usefull. I didn't know about the tabbing order and setting it, but it solves my problem if I just use the Tab key to move between input boxes. And uicontrol, as you suggest, also works with using the Enter key.
Leif Pedersen
Leif Pedersen comments to Geoff Hayes:
It worked!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Interactive Control and Callbacks dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by