How to set focus in GUI?
6 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Leif Pedersen
el 1 de Jun. de 2019
Comentada: Walter Roberson
el 6 de Jun. de 2019
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
0 comentarios
Respuesta aceptada
Geoff Hayes
el 2 de Jun. de 2019
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 comentarios
Geoff Hayes
el 3 de Jun. de 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
Walter Roberson
el 6 de Jun. de 2019
Más respuestas (0)
Ver también
Categorías
Más información sobre Migrate GUIDE Apps en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!