Problem in retreiveng textbox string in uicontrol created dialog

2 ビュー (過去 30 日間)
Cristian Berceanu
Cristian Berceanu 2019 年 9 月 6 日
コメント済み: Adam Danz 2019 年 9 月 9 日
Hello,
I have the following function, which creates a dialog with two textboxex (Textbox1 and Textbox2 and a checkbox). I would like two things to happen as I type text in Textbox 1:
  • toggle the checkbox
  • programatically copy the text from Textbox1 to Textbox2
Toggling the checkbox always works, however programatically copying the same text in Textbox 2 only works if I add a breakpoint in the Textbox_callback function. If I do not add this breakpoint, then Textbox2 will only display the "original text" text each time I change the text in Textbox1.
What am I doing wrong?
function choosedialog
d = dialog('Position',[300 300 250 200],'Name','Serial Number');
Textbox1 = uicontrol('Parent',d,...
'Style','edit',...
'Position',[20 100 210 40],...
'String','original text',...
'KeyPressFcn',@Textbox_callback);
ck1 = uicontrol('Parent',d,...
'Style','checkbox',...
'Position',[20 150 210 40],...
'String','Checkbox');
Textbox2 = uicontrol('Parent',d,...
'Style','edit',...
'Position',[20 40 210 40],...
'String','');
%focus automatically on textbox
uicontrol(Textbox1);
% Wait for d to close before running to completion
uiwait(d);
function Textbox_callback(Textbox1,event)
ck1.Value = ~ck1.Value;
Textbox2.String = Textbox1.String;
end
end
  3 件のコメント
Walter Roberson
Walter Roberson 2019 年 9 月 6 日
Every time you step through, the dialog loses focus, which is the trigger to update the String property.
Adam Danz
Adam Danz 2019 年 9 月 9 日
Thanks, Walter.
I imagine a callback function that could first change the focus to, say, the main figure, then execute a timer that would copy the string from textbox1 to textbox2 after a fraction of second delay, and then change the focus back to the first textbox. That way the focus is changed on each key stroke and the delayed timer, if timed properly, could do the copy-paste work after the trigger, while the focus is returned to the main textbox.

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

採用された回答

Walter Roberson
Walter Roberson 2019 年 9 月 6 日

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMigrate GUIDE Apps についてさらに検索

タグ

製品


リリース

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by