User interface 为什么可以';是否从可编辑的文本框复制值?
我有一个GUI,其中一些值显示在图形界面中。由于某些原因,我无法用鼠标复制这些值。我可以选择文本,但在所选文本上单击鼠标右键时,不会出现下拉菜单。我一直在到处找。我错过了什么 如果需要,您应该使用User interface 为什么可以';是否从可编辑的文本框复制值?,user-interface,matlab,textbox,copy,right-click,User Interface,Matlab,Textbox,Copy,Right Click,我有一个GUI,其中一些值显示在图形界面中。由于某些原因,我无法用鼠标复制这些值。我可以选择文本,但在所选文本上单击鼠标右键时,不会出现下拉菜单。我一直在到处找。我错过了什么 如果需要,您应该使用uicontextmenuuicontrol自己实现上下文菜单,并使用uimenu向其添加项目。请参见此处:右键单击时,默认情况下可编辑文本框不会显示上下文菜单,但如果要将文本复制到剪贴板,有几种方法可以解决此问题: hFigure = figure;
uicontextmenu
uicontrol自己实现上下文菜单,并使用uimenu
向其添加项目。请参见此处:右键单击时,默认情况下可编辑文本框不会显示上下文菜单,但如果要将文本复制到剪贴板,有几种方法可以解决此问题:
hFigure = figure; %# Create a figure
hEdit = uicontrol(hFigure,'Style','edit',... %# Create an editable text box
'String','Enter your name here',...
'Position',[30 50 130 20]);
hCMenu = uicontextmenu; %# Create a context menu
uimenu(hCMenu,'Label','Copy',... %# Create a menu item
'Callback',@(hObject,eventData) clipboard('copy',get(hEdit,'String')));
set(hEdit,'UIContextMenu',hCMenu); %# Add context menu to control
hFigure = figure; %# Create a figure
hEdit = uicontrol(hFigure,'Style','edit',... %# Create an editable text box
'String','Enter your name here',...
'Position',[30 50 130 20]);
hCMenu = uicontextmenu; %# Create a context menu
uimenu(hCMenu,'Label','Copy',... %# Create a menu item
'Callback',@(hObject,eventData) clipboard('copy',get(hEdit,'String')));
set(hEdit,'UIContextMenu',hCMenu); %# Add context menu to control
现在,您可以右键单击控件,打开一个菜单,其中有一个选项:“复制”。请注意,通过选择此菜单项,它会将可编辑文本字符串复制到剪贴板,而无需首先高亮显示文本function right_click_copy(hObject,eventData)
hFigure = get(hObject,'Parent'); %# Get the parent object
while ~strcmp(get(hFigure,'Type'),'figure') %# Loop until it is a figure
hFigure = get(hFigure,'Parent'); %# Keep getting the parents
end
if strcmp(get(hFigure,'SelectionType'),'alt') %# Check for a right click
clipboard('copy',get(hObject,'String')); %# Copy the object string to
%# the clipboard
end
end
此函数使用父图形的图标来检查按下了哪个鼠标按钮,并使用此函数将对象字符串复制到剪贴板。现在,您可以按如下方式创建可编辑文本控件:
hFigure = figure; %# Create a figure
hEdit = uicontrol(hFigure,'Style','edit',... %# Create an editable text box
'String','Enter your name here',...
'Position',[30 50 130 20],...
'ButtonDownFcn',@right_click_copy);
这是三个选项中最快、最简单的选项,因为只需单击鼠标一次即可将可编辑文本字符串复制到剪贴板您只是想使可编辑文本框“启用”吗 set(handles.editbox1,'Enable','on') (假设您拥有该GUI对象的“句柄”。)
这将使编辑框可编辑。它被称为上下文菜单,您是对的-默认情况下MTALAB中没有。但是您仍然可以使用Ctrl+C