简体   繁体   English

带有下拉菜单的TToolbar按钮显示为灰色

[英]TToolbar Button with dropdown menu greyed out

I'm having issues getting a TToolbar Button to appear "enable" 我在让TToolbar按钮显示“启用”时遇到问题

The button has an Action assigned to it - which is fire by the OnClick event 该按钮有一个分配给它的动作 - 由OnClick事件触发

It is also setup with a Drop Down Menu, which has 2 options on it, both of which are enabled, and both of which fire off when clicked. 它还设置了一个下拉菜单,它有2个选项,两个选项都已启用,并且两个选项在单击时都会触发。

Despite all this the TToolbar Button steadfastly remains greyed out, but accepts the clicks. 尽管如此,TToolbar Button仍然保持灰色,但接受点击。

Any suggestions? 有什么建议么?

You're doing things wrong. 你做错了。 :-) :-)

When using actions, you don't use the button's OnClick event - you put the code in the action's OnExecute event instead (because that's what's executing - the action - and not the button). 使用操作时,您不使用按钮的OnClick事件 - 您将代码放在操作的OnExecute事件中(因为这是正在执行的操作 - 操作 - 而不是按钮)。 When an action is assigned to the control, the control cannot be enabled until there's a handler for the TAction.OnExecute . 当为控件分配操作时,只有TAction.OnExecute的处理程序才能启用该TAction.OnExecute

The reason for using actions is so you can put the code in a single place (events related to the action), and then every single control attached to that action uses that common code to perform the same functionality. 使用操作的原因是您可以将代码放在一个位置(与操作相关的事件),然后附加到该操作的每个控件都使用该公共代码来执行相同的功能。 Editing the code in that single location means all controls attached to that action see the same changes. 在该单个位置编辑代码意味着附加到该操作的所有控件都会看到相同的更改。

If there's nothing attached to the TAction.OnExecute event, the control has nothing to do if it was selected (clicked), and so there's no reason to enable it in the first place. 如果TAction.OnExecute事件没有附加任何内容,则控件如果被选中(单击)则无需执行任何操作,因此没有理由首先启用它。

In case someone else comes across this, I just had this problem (using Delphi 10.2 Tokyo). 如果其他人遇到这个问题,我就遇到了这个问题(使用Delphi 10.2 Tokyo)。

For some reason, the "EnableDropdown" property on the TToolButton caused the button to to be greyed out when set to true. 出于某种原因,TToolButton上的“EnableDropdown”属性导致按钮在设置为true时显示为灰色。 Setting this property to false seems to have resolved the problem for me (the dropdown menu remains functional anyway). 将此属性设置为false似乎已解决了我的问题(无论如何,下拉菜单仍然有效)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM