为什么我无法从可编辑文本框中复制值?

发布于 2024-10-07 04:54:15 字数 203 浏览 7 评论 0原文

我有一个 GUI,其中一些值显示在 可编辑文本框中。由于某种原因,我无法用鼠标复制这些值。我可以选择文本,但右键单击所选文本时不会出现下拉菜单。我一直在到处寻找。我缺少什么?

I have a GUI where some values are displayed in an editable textbox. For some reason I cannot copy those values with the mouse. I can select the text, but no drop-down menu appears when I right-click on the selected text. I have been looking all over the place. What am I missing?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

燕归巢 2024-10-14 04:54:15

如果需要,您应该自己实现上下文菜单,方法是使用 uicontextmenu uicontrol,并使用 uimenu 向其中添加项目。请参阅此处:http://www.mathworks.com/help/techdoc/ref/ uicontextmenu.html

You should implement the context menu yourself, if you need one, by using uicontextmenu uicontrol, and adding items to it using uimenu. See here: http://www.mathworks.com/help/techdoc/ref/uicontextmenu.html

方圜几里 2024-10-14 04:54:15

确实,当您右键单击时,可编辑文本框默认不会显示上下文菜单,但如果您想将文本复制到剪贴板,有几种方法可以解决此问题:

  1. As Mikhail 在他的评论中提到,您仍然可以突出显示文本并按 Ctrl + C将其复制到剪贴板。

  2. 正如Itamar 在他的回答中提到< /a>,您可以使用函数 UICONTEXTMENUUIMENU。以下是使用函数 CLIPBOARD 添加可编辑文本的示例实现字符串到剪贴板:

    hFigure = 图; %# 创建一个图形
    hEdit = uicontrol(hFigure,'Style','edit',... %# 创建可编辑文本框
                      '字符串','在此处输入您的名字',...
                      '位置',[30 50 130 20]);
    hCMenu = uicontextmenu; %# 创建上下文菜单
    uimenu(hCMenu,'Label','Copy',... %# 创建菜单项
           '回调',@(hObject,eventData) 剪贴板('复制',get(hEdit,'字符串')));
    设置(hEdit,'UIContextMenu',hCMenu); %# 添加上下文菜单来控制
    

    现在您可以右键单击该控件以显示一个菜单,其中包含一个选项:“复制”。请注意,通过选择此菜单项,它将把可编辑的文本字符串复制到剪贴板,而不必先突出显示文本。

  3. 您可以设置'ButtonDownFcn' 可编辑文本框的属性,以便右键单击该控件将自动将文本字符串复制到剪贴板,而无需突出显示文本或选择菜单项。首先,您必须将此 m 文件函数保存到路径:

    函数 right_click_copy(hObject,eventData)
      hFigure = get(hObject,'父级'); %# 获取父对象
      while ~strcmp(get(hFigure,'Type'),'figure') %# 循环直到它是一个图形
        hFigure = get(hFigure,'父级'); %# 继续获取父母
      结尾
      if strcmp(get(hFigure,'SelectionType'),'alt') %# 检查是否右键单击
        剪贴板('复制',获取(hObject,'字符串')); %# 将对象字符串复制到
                                                     %# 剪贴板
      结尾
    结尾
    

    此函数使用'SelectionType' 父图窗的属性 来检查按下了哪个鼠标按钮以及 CLIPBOARD 函数将对象字符串复制到剪贴板。现在您可以创建可编辑文本控件,如下所示:

    hFigure = 图; %# 创建一个图形
    hEdit = uicontrol(hFigure,'Style','edit',... %# 创建可编辑文本框
                      '字符串','在此处输入您的名字',...
                      '位置',[30 50 130 20],...
                      'ButtonDownFcn',@right_click_copy);
    

    这是三个选项中最快、最简单的选项,因为它只需单击一次鼠标即可将可编辑文本字符串复制到剪贴板。

It's true that editable text boxes don't bring up a context menu by default when you right click, but there are a few ways around this if you're wanting to copy text to the clipboard:

  1. As Mikhail mentions in his comment, you can still highlight the text and press Ctrl + C to copy it to the clipboard.

  2. As Itamar mentions in his answer, you can create your own context menu for the editable text box using the functions UICONTEXTMENU and UIMENU. Here's a sample implementation that uses the function CLIPBOARD to add the editable text string to the clipboard:

    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
    

    Now you can right click on the control to bring up a menu with one option: "Copy". Note that by selecting this menu item it will copy the editable text string to the clipboard without having to highlight the text first.

  3. You can set the 'ButtonDownFcn' property for your editable text box so that a right click on the control will automatically copy the text string to the clipboard without having to highlight the text or select a menu item. First you would have to save this m-file function to the path:

    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
    

    This function uses the 'SelectionType' property of the parent figure to check which mouse button was pressed and the CLIPBOARD function to copy the object string to the clipboard. Now you can create your editable text control as follows:

    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);
    

    This is the quickest and easiest option of the three, since it involves only a single mouse click to copy the editable text string to the clipboard.

蝶…霜飞 2024-10-14 04:54:15

您只是想让可编辑文本框“启用”吗?

set(handles.editbox1,'启用','on');

(假设您拥有该 GUI 对象的“句柄”。)

这应该使编辑框可编辑。

Did you just want to make the editable textbox 'Enable'?

set(handles.editbox1,'Enable','on');

(assuming that you have the 'handle' to that GUI object.)

This should make the edit box editable.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文