vba 从另一个控件的回调更新 iRibbon 控件的内容
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18004053/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Updating contents of an iRibbon control from another control's callback
提问by Adam Lawrence
Back in the old days of VBA, we used to be able to directly access controls on a form by name. I'm a little perplexed by how to do this in VBA 2010 (or if it's even possible any longer).
回到 VBA 的旧时代,我们曾经能够通过名称直接访问表单上的控件。我对如何在 VBA 2010 中执行此操作感到有些困惑(或者是否还有可能)。
Say I have a ribbon control with a dropdown list called "channelList", and elsewhere on the ribbon I have a textbox called "labelText". Each of these items has a unique callback function - when I type something into labelText, its callback fires, and when I select an item from the channelList listbox, its callback fires with the list item passed as an argument.
假设我有一个带有名为“channelList”的下拉列表的功能区控件,在功能区的其他地方我有一个名为“labelText”的文本框。这些项目中的每一个都有一个独特的回调函数——当我在 labelText 中输入一些东西时,它的回调会触发,当我从 channelList 列表框中选择一个项目时,它的回调会以列表项作为参数传递。
Where I'm stumped by is how I would update the labelText textbox contents with 'something' from within the channelList callback.
我感到困惑的是我将如何使用 channelList 回调中的“某物”更新 labelText 文本框内容。
Is there a way to directly access the textbox control from within the listbox callback, or must I generate some sort of event? What method or function would I use to set the text value for the control? (Do I need to cast the IRibbonControl object to something?)
有没有办法从列表框回调中直接访问文本框控件,或者我必须生成某种事件?我将使用什么方法或函数来设置控件的文本值?(我需要将 IRibbonControl 对象强制转换为某些东西吗?)
采纳答案by Adam Lawrence
The solution was a combination of an answer and the comments, so here goes:
解决方案是答案和评论的结合,所以这里是:
- Add a "getText" callback subroutine name to the Ribbon XML, specific to the "labelText" editbox.
- 将“getText”回调子例程名称添加到功能区 XML,特定于“labelText”编辑框。
editBox id="labelText" label="Text:" sizeString="xxxxxxxxxx" onChange="TextboxCallback" getText="UpdateTextBoxText" screentip="Channel label" supertip="Limited to 10 characters. Press Enter once finished typing."
- In the combo box callback function, set the desired editbox text to a global and call Ribbon.InvalidateControl with "labelText" as the argument.
- 在组合框回调函数中,将所需的编辑框文本设置为全局并使用“labelText”作为参数调用 Ribbon.InvalidateControl。
MyRibbon.InvalidateControl "labelText"
- Implement the editbox callback, passing a handle to the ribbon and another variable ByRef to contain the 'stuff' to be updated. Use the global to update the control's text via the ByRef argument.
- 实现编辑框回调,将句柄传递给功能区和另一个变量 ByRef 以包含要更新的“东西”。使用全局通过 ByRef 参数更新控件的文本。
Sub UpdateTextBoxText(control As IRibbonControl, ByRef returnedVal) Select Case (control.id) Case "labelText" returnedVal = LabelText End Select End Sub
I guess this is "progress". labelText.Value = "blah" is fartoo simple.
我想这就是“进步”。labelText.Value =“嗒嗒”是远太简单了。
回答by Doug Glancy
Take a look at the Ribbon.Invalidate
method. When you "invalidate" the ribbon you basically reset it, and in that moment you can set the properties of controls on the ribbon based on whatever you can track in that moment. In order to do so, you need to have Control.GetEnabled
, GetVisible
, etc., subroutines in your VBA.
看一下Ribbon.Invalidate
方法。当您“使”功能区“无效”时,您基本上将其重置,在那一刻,您可以根据当时可以跟踪的任何内容设置功能区上控件的属性。为了做到这一点,你需要有Control.GetEnabled
,GetVisible
等等,在VBA子程序。
You can also invalidate individual controls with Ribbon.InvalidateControl
.
您还可以使用 使单个控件无效Ribbon.InvalidateControl
。
Here's a link that might help: http://sourcedaddy.com/ms-excel/resetting-controls.html
这是一个可能有帮助的链接:http: //sourcedaddy.com/ms-excel/resetting-controls.html