Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在MatlabGUI中单击鼠标清除编辑框_Matlab_User Interface_Matlab Guide - Fatal编程技术网

在MatlabGUI中单击鼠标清除编辑框

在MatlabGUI中单击鼠标清除编辑框,matlab,user-interface,matlab-guide,Matlab,User Interface,Matlab Guide,我想在MatlabGUI中有一个“编辑”框,上面写着“这里输入搜索”。 当用户在框内单击时,我希望“此处键入搜索”消失,并给用户一个空的编辑框开始键入 有什么想法吗?至少在我的系统上,当我使用以下代码设置用户输入框/窗口时 prompt = 'Enter search terms:'; dlg_title = 'My input box'; num_lines = 1; defAns = {'TYPE_SERACH_HERE'}; answer = inputdlg(prompt,

我想在MatlabGUI中有一个“编辑”框,上面写着“这里输入搜索”。 当用户在框内单击时,我希望“此处键入搜索”消失,并给用户一个空的编辑框开始键入


有什么想法吗?

至少在我的系统上,当我使用以下代码设置用户输入框/窗口时

prompt    = 'Enter search terms:';
dlg_title = 'My input box';
num_lines = 1;
defAns    = {'TYPE_SERACH_HERE'};

answer = inputdlg(prompt, dlg_title, num_lines, defAns);
默认文本
TYPE\u SEARCH\u HERE
将突出显示,因此我可以开始键入以替换为所需内容

编辑或者,如果您有一个现有的
uicontrol
编辑框,您可以执行如下操作:

function hedit = drawbox()

  hedit = uicontrol('Style', 'edit',...
      'String', 'deafult',...
      'Enable', 'inactive',...
      'Callback', @print_string,...
      'ButtonDownFcn', @clear);

end

function clear(hObj, event) %#ok<INUSD>

  set(hObj, 'String', '', 'Enable', 'on');
  uicontrol(hObj); % This activates the edit box and 
                   % places the cursor in the box,
                   % ready for user input.

end

function print_string(hObj, event) %#ok<INUSD>

  get(hObj, 'String')

end
函数hedit=drawbox()
hedit=uicontrol('样式','编辑',。。。
'字符串','死亡',。。。
'启用','不活动',。。。
“回调”,@print\u字符串,。。。
“ButtonDownFcn”,清除);
结束
功能清除(hObj,事件)%#正常
设置(hObj,'String','Enable','on');
uicontrol(hObj);%这将激活编辑框并
%将光标放置在框中,
%准备好供用户输入。
结束
函数打印字符串(hObj,事件)%#正常
get(hObj,‘String’)
结束

克里斯,你必须点击uicontrol边框以使按钮关闭。如果您在编辑框内单击,则不会发生此问题。好的,因此我有一个解决此问题的方法,它可以完美地工作

然而,我很沮丧,因为我完全不知道为什么它会起作用

  • 在指南中创建一个编辑文本框,然后右键单击它以打开“属性检查器”
  • 将文本“在此处键入文本”添加到“字符串”属性
  • 找到属性nammed“Enable”并将其切换为“inactive”
  • 创建buttonDownFnc(也可以在property inspector中完成)
  • 使用以下代码:

    函数myeditboxtaggoesher_ButtonDownFcn(hObject、eventdata、handles)

    %将“启用”状态设置为打开

    设置(hObject,'Enable','On')

    %创建UI控件

    uicontrol(handles.myeditboxtaggoesher)


  • 如果有人能解释为什么uicontrol在鼠标左键点击时突出显示文本,那就太好了

    Hooplator15,它之所以能工作,是因为编辑文本就像关闭启用时的按钮:

    • 如果Enable==“on”(编辑文本启用),则在鼠标按入5像素边框时执行函数_ButtonDownFcn

    • 否则,它会在鼠标按下5像素边框或编辑文本(如按钮)时执行


    不得不点击两次,这会使目的落空。你知道在编辑框中单击时如何突出显示文本吗?谢谢,但这似乎不容易做到。见下面的答案