为什么我无法从可编辑文本框中复制值?
我有一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果需要,您应该自己实现上下文菜单,方法是使用
uicontextmenu
uicontrol,并使用uimenu
向其中添加项目。请参阅此处:http://www.mathworks.com/help/techdoc/ref/ uicontextmenu.htmlYou should implement the context menu yourself, if you need one, by using
uicontextmenu
uicontrol, and adding items to it usinguimenu
. See here: http://www.mathworks.com/help/techdoc/ref/uicontextmenu.html确实,当您右键单击时,可编辑文本框默认不会显示上下文菜单,但如果您想将文本复制到剪贴板,有几种方法可以解决此问题:
As Mikhail 在他的评论中提到,您仍然可以突出显示文本并按 Ctrl + C将其复制到剪贴板。
正如Itamar 在他的回答中提到< /a>,您可以使用函数 UICONTEXTMENU 和 UIMENU。以下是使用函数 CLIPBOARD 添加可编辑文本的示例实现字符串到剪贴板:
现在您可以右键单击该控件以显示一个菜单,其中包含一个选项:“复制”。请注意,通过选择此菜单项,它将把可编辑的文本字符串复制到剪贴板,而不必先突出显示文本。
您可以设置
'ButtonDownFcn'
可编辑文本框的属性,以便右键单击该控件将自动将文本字符串复制到剪贴板,而无需突出显示文本或选择菜单项。首先,您必须将此 m 文件函数保存到路径:此函数使用
'SelectionType'
父图窗的属性 来检查按下了哪个鼠标按钮以及 CLIPBOARD 函数将对象字符串复制到剪贴板。现在您可以创建可编辑文本控件,如下所示:这是三个选项中最快、最简单的选项,因为它只需单击一次鼠标即可将可编辑文本字符串复制到剪贴板。
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:
As Mikhail mentions in his comment, you can still highlight the text and press Ctrl + C to copy it to the clipboard.
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:
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.
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: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: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.
您只是想让可编辑文本框“启用”吗?
(假设您拥有该 GUI 对象的“句柄”。)
这应该使编辑框可编辑。
Did you just want to make the editable textbox 'Enable'?
(assuming that you have the 'handle' to that GUI object.)
This should make the edit box editable.