Can i set all text boxes to their default value by using only one command
5 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Shameer Parmar
2016-6-14
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 个评论
clear all
2017-2-27
编辑:Walter Roberson
2017-2-27
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);
更多回答(2 个)
Jos (10584)
2016-6-14
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
2016-5-17
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 个评论
Walter Roberson
2016-5-18
set( findall(0, 'style', 'edit'), 'string', '')
The default value of a uicontrol of style edit is the empty string.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 File Operations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!