How to set focus in GUI?
6 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Leif Pedersen
am 1 Jun. 2019
Kommentiert: Walter Roberson
am 6 Jun. 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 Kommentare
Akzeptierte Antwort
Geoff Hayes
am 2 Jun. 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 Kommentare
Geoff Hayes
am 3 Jun. 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
am 6 Jun. 2019
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Migrate GUIDE Apps finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!