Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>ActiveX events are handled via COM, so you need to delve in there a bit <em>unfortunately</em>.</p> <p>The thing to remember with COM is that everything is handled via interfaces, so you normally need to create two interfaces, one for any properties and one for your events.</p> <p>The key for events is marking your class with the ComSourceInterfaces attribute, which is described by MSDN as "Identifies a list of interfaces that are exposed as COM event sources for the attributed class."</p> <p>This simple class structure should work for you (it has for me in the past).</p> <pre><code>namespace MyActiveX { [Guid("Your-GUID") ,InterfaceType(ComInterfaceType.InterfaceIsIDispatch)] public interface IActiveXEvents { [DispId(1)] void OnMouseClick(int index); } [Guid("Another-GUID"),InterfaceType(ComInterfaceType.InterfaceIsIDispatch)] public interface IActiveX { //[DispId(1)] // Any properties you want here like this // string aProperty { get; set; } } [ComVisible(true)] [Guid("Yet-Another-GUID"), ClassInterface(ClassInterfaceType.None)] [ProgId("MyActiveX")] [ComSourceInterfaces(typeof(IActiveXEvents))] public partial class MyActiveX : UserControl, IActiveX { public delegate void OnMouseClickHandler(int index); public event OnMouseClickHandler OnMouseClick; // Dummy Method to use when firing the event private void MyActiveX_nMouseClick(int index) { } public MyActiveX() { InitializeComponent(); // Bind event this.OnMouseClick = new OnMouseClickHandler(this.MyActiveX_MouseClick) } public void FireTheEvent() { int index = -1; this.OnMouseClick(index); } } } </code></pre> <p>If you don't need any properties you can just exclude the IActiveX interface. Also if you are going to use the Click event, you will need to mark it as <strong>new</strong> to pass it to COM.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload