Can i set all text boxes to their default value by using only one command
5 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
mania online
le 17 Mai 2016
Modifié(e) : Stephen23
le 27 Fév 2017
I 'm using this command to set textbox to its default value I have 17 text boxes in my GUI. I want to reset all of them by using command only one time instead of calling this 17 times. Is it possible?
set(handles.text1, 'string', 'default');
0 commentaires
Réponse acceptée
Shameer Parmar
le 14 Juin 2016
Hello Mania,
You can achieve your requirement, by creating new function in your code file (i.e. in .m file of your GUI).
1. Simply create new function at the end of your actual code as shown below:
function default(hObject, handles)
set(handles.text1, 'string', 'WhateverYouWant_But_InStringFormat');
set(handles.text2, 'string', 'WhateverYouWant_But_InStringFormat');
set(handles.text3, 'string', 'WhateverYouWant_But_InStringFormat');
.
.
.
set(handles.text17, 'string', 'WhateverYouWant_But_InStringFormat');
guidata(hObject, handles);
end
2. Call this function in the Opening function of your GUI as follows:
function xxxxxx_OpeningFcn(hObject, eventdata, handles, varargin)
% lines of code
.
.
default(hObject, handles);
.
.
guidata(hObject, handles);
end
You can call function "default()" wherever you want, in callback function of any button/field of your GUI to make the text value default, as per your requirement.
Try for this and let me know if you face any issue.
1 commentaire
clear all
le 27 Fév 2017
Modifié(e) : Walter Roberson
le 27 Fév 2017
Thank you so much for your help.
I tried and it works(the edit box shows default vaule).
But the problem is that I have to click(or press enter) the edit box to ensure that the box has value.
If I do not click the edit box, then edit box do not perceive the default value.
It would be grateful if you let me know how this is done.
Thanks
This is my code.
% ================================================================
function aaaaaGUI_OpeningFcn(hObject, eventdata, handles, varargin)
% lines of code
...
...
default_aaaaa(hObject, handles);
...
...
guidata(hObject, handles);
% ================================================================
function edit_ac_Callback(hObject, eventdata, handles)
global critical_aaaaa
critical_aaaa = str2double(get(handles.edit_aaaaa,'string'));
% ================================================================
function edit_aaaaa_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% ================================================================
function default_aaaaa(hObject, handles)
set(handles.edit_aaaaa,'string','500')
guidata(hObject, handles);
Plus de réponses (2)
Jos (10584)
le 14 Juin 2016
This task would be utterly trivial if you had put the handles to the boxes into an array on creation!
handles.text(1) = ..
handles.text(2) = ..
...
set(handles.text,'String','') ;
Walter Roberson
le 17 Mai 2016
In MATLAB, textbox objects do not have a default value; or if they do, it is the empty string. textbox objects are also used for output, not for input; do you perhaps mean editbox?
set( findall( ancestor(handles.edit1, 'figure'), 'style', 'edit'), 'string', 'WhatEverYouWant')
3 commentaires
Walter Roberson
le 18 Mai 2016
set( findall(0, 'style', 'edit'), 'string', '')
The default value of a uicontrol of style edit is the empty string.
Voir également
Catégories
En savoir plus sur Platform and License dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!