필터 지우기
필터 지우기

Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

How can I read the string in an input box while editing?

조회 수: 1 (최근 30일)
Steven Landis
Steven Landis 2018년 6월 27일
마감: MATLAB Answer Bot 2021년 8월 20일
I have an input box:
this.gui.p1.name_input = uicontrol(...
'Parent', panel,...
'Style', 'edit',...
'String', 'Search',...
'FontSize', this.font.body,...
'HorizontalAlignment', 'left',...
'KeyPressFcn', @this.on_name_change...
);
With a callback function:
function on_name_change(this, ~, ~)
fprintf('Name changed to %s\n', get(elem, 'String'));
end
When I type in the input box, the 'String' property doesn't get updated until I press enter or leave the input box.
For example, if the input box initially had the string 'Search', this function will print out
Search
Search
Search
for every time I press a key.
The preferred behavior would be (if I pressed backspace 3 times)
Searc
Sear
Sea
Update:
By adding a drawnow into the update function, the text correctly updates when I press enter. However, it doesn't work for any other keys.
function on_name_change(this, elem, ~)
drawnow
fprintf('changed to %s\n', get(elem, 'String_I'));
end

답변 (0개)

이 질문은 마감되었습니다.

제품


릴리스

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by