フィルターのクリア

Can i set all text boxes to their default value by using only one command

10 ビュー (過去 30 日間)
mania online
mania online 2016 年 5 月 17 日
編集済み: Stephen23 2017 年 2 月 27 日
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');

採用された回答

Shameer Parmar
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
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)
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','') ;
  1 件のコメント
Stephen23
Stephen23 2017 年 2 月 27 日
編集済み: Stephen23 2017 年 2 月 27 日
Yes, this is the best answer! When graphics handles are explicitly stored and accessed then the code will be clearer, faster, and more robust.
Avoid the problem by writing better code in the first place:

サインインしてコメントする。


Walter Roberson
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 件のコメント
mania online
mania online 2016 年 5 月 18 日
This is not working. I want to set all static textboxes to their default value by a single command.
Walter Roberson
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 ExchangeMigrate GUIDE Apps についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by