在 MATLAB GUI 中单击鼠标即可清除编辑框
我想在 MATLAB GUI 中有一个“编辑”框,上面写着“在此处键入搜索”。 当用户在框内单击时,我希望“此处类型搜索”消失,并为用户提供一个空的编辑框以开始输入...
有什么想法吗?
I want to have an "edit" box in a MATLAB GUI that says "TYPE SEARCH HERE".
When the user clicks inside the box I want the "TYPE SEARCH HERE" to disappear and give the user an empty edit box to start typing in...
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
至少在我的系统上,当我使用以下代码设置用户输入框/窗口时,
默认文本
TYPE_SEARCH_HERE
会突出显示,因此我可以开始输入以将其替换为我想要的内容。编辑 或者,如果您有现有的
uicontrol
编辑框,您可以执行如下操作:At least on my system, when I use the follow code to set up a user input box/window
the default text
TYPE_SEARCH_HERE
appears highlighted, so I can just start typing to replace it with what ever I want.Edit Alternatively, if you have an existing
uicontrol
edit box you could do something like the following:Chris,您必须单击 uicontrol 边框才能发生 ButtonDownFcn。如果您在编辑框内单击,则不会发生这种情况
Chris, you've got to click in the uicontrol border to make the ButtonDownFcn happen. It won't happen if you click inside the edit box
好的,我已经找到了解决问题的方法,并且完美无缺!
然而,我很沮丧,因为我完全不知道它为什么起作用...
使用以下代码:
函数 myEditBoxTagGoesHere_ButtonDownFcn(hObject, eventdata, 句柄)
% 将“启用”状态切换为 ON
set(hObject, '启用', '开启');
%创建UI控件
uicontrol(handles.myEditBoxTagGoesHere);
如果有人能解释为什么 uicontrol 在单击鼠标左键时突出显示文本,那就太好了!
Okay, so I have a solution to the problem and it works flawlessly!!
However, I am quite upset because I have absolutely no idea WHY it works...
Use following code:
function myEditBoxTagGoesHere_ButtonDownFcn(hObject, eventdata, handles)
% Toggel the "Enable" state to ON
set(hObject, 'Enable', 'On');
% Create UI control
uicontrol(handles.myEditBoxTagGoesHere);
If someone could explain why uicontrol highlights the text upon left mouse click, that would be great!
Hooplator15,它之所以有效,是因为当启用关闭时,编辑文本就像按钮:
如果 Enable == 'on'(编辑文本启用),函数 _ButtonDownFcn 将在 5 像素边框内按下鼠标时执行;
否则,它会在 5 像素边框内或编辑文本上方按下鼠标时执行,如按钮。
Hooplator15, it works because edit texts are like push buttons when Enable is Off:
If Enable == 'on' (edit text Enable), the function _ButtonDownFcn executes on mouse press in 5 pixel border;
Otherwise, it executes on mouse press in 5 pixel border or over edit text, like a button.