Can i set all text boxes to their default value by using only one command
10 ビュー (過去 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 で Migrate GUIDE Apps についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!