我通过图中的注释(.)创建了两个文本框。它们的大部分属性已经被定义;回调函数可以在窗口中进行拖放操作。我为盒子创建了一个 uicontextmenu。右键单击可以选择功能列表以进行后续操作。
我尝试添加的操作之一涉及在两个框之间交换字符串。我需要获取当前右键单击的框中的字符串,该字符串应与我随后左键单击的框中的字符串交换。我可以获得有关如何扩展 uimenu 功能以便它注册后续左键单击的建议吗?
I have created two textboxes via annotation(.) in a figure. Most of their properties have been defined; and the callback function enables drag and drop motion in the window. I created a uicontextmenu for the boxes. On right click a list of functions can be chosen from for subsequent action.
One of the actions I am trying to add involves swapping strings between the two boxes. I need to get the string of the box I currently right-clicked, which should swap with the string in the box I subsequently left-click. Can I get advice on how to go about extending the uimenu function so that it registers the subsequent left-click?
发布评论
评论(1)
您将需要手动存储最后单击的框。如果您使用 GUIDE 来设计 GUI,请使用传递给回调函数的
handles
结构。否则,如果您以编程方式生成组件,则嵌套回调函数可以访问其封闭函数内定义的变量。编辑
这是一个完整的示例:右键单击并从上下文菜单中选择“交换”,然后选择另一个文本框来交换字符串(左键单击)。请注意,我必须禁用/启用两个步骤之间的文本框才能触发 ButtonDownFcn (请参阅此 页面 进行解释)
You will need to manually store the last clicked box. If you are using GUIDE to design your GUI, use the
handles
structure which gets passed around to callback functions. Otherwise if you programmatically generate the components, then nested callback functions have access to variables defined inside their enclosing functions.EDIT
Here is a complete example: right-click and select "Swap" from context menu, then choose the other textbox to swap strings with (left-click). Note that I had to disable/enable the textboxes in-between the two steps to be able to fire the ButtonDownFcn (see this page for an explanation)