注册ActiveX控件的OnClick事件 [英] Registering to OnClick event of ActiveX control

查看:184
本文介绍了注册ActiveX控件的OnClick事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

不幸的是,我无法弄清楚如何执行以下操作:

Unfortunately, I have not been able to figure out how to do the following:

我正在VSTO / .NET / C#中开发Excel加载项。

I am developing an Excel Add-In in VSTO / .NET / C#.

我已经能够找到如何在工作表中获取对ActiveX控件的引用。可以通过工作表.OLEObjects集合。

I have been able to find out how to get references to the ActiveX controls in a worksheet. It is possible via the worksheet.OLEObjects collection.

如果我知道按钮的名称,我可以搜索该集合的特定按钮。

I can search that collection for a particular button if I know the name of the button. So far, so good.

但现在:如何注册在点击按钮时被调用的事件处理程序?

But now: How can I register an event handler that gets called when the button is clicked?

推荐答案

我正在寻找同样的解决方案,但还没有找到。
您建议使用表单控件[A] 而不是 ActiveX控件[B]

I'm looking for the same solution but haven't found yet. What you suggest is to use Form Controls [A] instead of ActiveX Controls [B]:

否则你必须将它们从[A]转换成[B],当循环通过 worksheet.OLEObjects
您是否找到与ActiveX控件相同的方法?
我还没有找到一种方法来正确地引用他们的 dll 与表单[A]:... Microsoft.Vbe.Interop.Forms.dll

Otherwise you have to cast them somehow from [A] to [B], when loop through worksheet.OLEObjects. Do you find a way to the same with the ActiveX Controls? I haven't found a way yet to properly reference to their dll as for the forms [A]: ...Microsoft.Vbe.Interop.Forms.dll

一旦[A]参考文献很好,我可以访问他们的事件。对于[B]可能会很高兴。

As soon as [A] is well references I can access their events. Would be nice to have the same for [B].

顺便说一下,您不能使用(发件人为Object,e ...)在事件头中的,使得如果使用多个按钮使用相同的处理程序,控制触发事件就变得困难了。

By the way, you cannot use (sender as Object, e...) in the event header, makes it difficult what control fired the event in case you using the same handler for multiple buttons.

这篇关于注册ActiveX控件的OnClick事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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