我怎么知道按下哪个MenuItem或按钮 [英] How can I know which MenuItem or button was pressed

查看:58
本文介绍了我怎么知道按下哪个MenuItem或按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个仪表板来选择(取消隐藏并激活)电子表格中的多个工作表之一:我在考虑带有菜单或多个按钮的UInstance.

I want to create a dashboard to select (unhide and make active) one of the several sheets in my spreadsheet: I was thinking of a UInstance with a menu or several buttons.

为每个按钮或MenuItem创建不同的ServerHandler(和不同的CallBack函数)似乎很困难,因为它们的数量仅在运行时知道.

It's seems difficult to create differents ServerHandler (and different CallBack functions) for each buttons or MenuItems, because their number is known only at run time.

在回调函数中使用EventInfo.parameter会容易得多,但是如果我不添加带有应该具有setName()方法的元素的CallbackElement,则此参数为空.

It would be much simpler to use the EventInfo.parameter in the callback function, but this parameter is empty if I don't add a CallbackElement with an element that should have a setName() method.

问题在于,令我大吃一惊的是,Button和MenuItem都没有setName方法!

The problem is that, to my big surprise, neither Buttons nor MenuItem do have the setName method!!!

我在这里错过了一些非常基本的东西吗?我似乎不认为按下菜单项的事件包含对启动事件本身的元素的引用是逻辑上的?

Am I missing something very basic here? I doesn't seems logic that a menu item pressing event would contains a reference to the element that started the event itself?

好吧,也许我应该还原到具有setName()方法的LIstBox ...

Ok, maybe I should revert to a LIstBox which has the setName() method...

谢谢劳罗

推荐答案

eventInfo包含调用处理程序的窗口小部件的ID.

The eventInfo contains the ID of the widget that calls the handler.

您可以使用处理程序函数中的 e.parameter [source] 来获取它(将ID作为字符串返回)

You can get it with e.parameter[source] in the handler function.(returns the ID as a string)

只需为所有按钮提供一个不同的ID,为所有按钮提供一个唯一的处理程序,就可以完成.(您可以将处理程序添加到父窗口小部件以简化代码,例如,如果您使用网格放置按钮,则将单个处理程序添加到网格中,它将对所有按钮都有效)

Just give a different ID to all of your buttons, one unique handler for all the buttons and you're done. (you can add the handler to the parent widget to simplify your code, for example if you use a grid to position the buttons add a single handler to the grid and it will work for all buttons)

这篇关于我怎么知道按下哪个MenuItem或按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆