[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework.interop

Getting events from an ActiveX control in a C# winform..

Jessica

3/19/2007 4:42:00 AM

Hi All,

I am having trouble getting events from an ActiveX control in my C# winform.
The activeX control is just a sample one developed by myself, and it fires
two stock events:-

KeyPress and Double click.

I did not do anything with the IConnectionPoint interface or whatecer as I
could add these events by right clicking on the Control class and specifying
which stock event I want to have.

Later in my C# form, I added this activeX control, and subscribed to one
these events (keypress) using the delegate created by the interop assemblies.
I could compile and run my form, but I am not getting the events from the
ActiveX control. The code looks like this:

public void KeyPressOnCtrl(object sender,
AxActiveXCtrlALib._DActiveXCtrlAEvents_KeyPressEvent e)
{
MessageBox.Show("Event from activeX control received");
}

public Form1()
{
InitializeComponent();
this.axActiveXCtrlA1.KeyPressEvent +=
new
AxActiveXCtrlALib._DActiveXCtrlAEvents_KeyPressEventHandler
(this.KeyPressOnCtrl);

}

Am I missing something here? Any help is greatly appreciated.

Thanks a lot,
Jessy
1 Answer

Dick Swager

3/21/2007 12:16:00 AM

0

I did something similar and did manage to get it to work but there was a lot
of trial and error, so I don't claim to have a great understanding. But
here are some thoughts.

The event handler, in your case KeyPressOnCtrl, must have exactly the same
prototype as the event in the COM object. It kinda looks like your second
argument is the event itself rather than an EventArgs type of thing. As an
experiment you could try some intrinsic arguments to see what happens.

Also you might want to check the typelib of the COM dll to make sure that
the names of the event and the event handler are what you think they are. I
had some problems figuring out what was what when I did it.

It looks like you are okay here but you need to make sure you have an valid
instance of the COM object when you subscribe the event handler delegate.

Dick


"Jessica" <Jessica@discussions.microsoft.com> wrote in message
news:994240A4-27C6-412A-80B7-E7BD78262BA2@microsoft.com...
> Hi All,
>
> I am having trouble getting events from an ActiveX control in my C#
> winform.
> The activeX control is just a sample one developed by myself, and it fires
> two stock events:-
>
> KeyPress and Double click.
>
> I did not do anything with the IConnectionPoint interface or whatecer as I
> could add these events by right clicking on the Control class and
> specifying
> which stock event I want to have.
>
> Later in my C# form, I added this activeX control, and subscribed to one
> these events (keypress) using the delegate created by the interop
> assemblies.
> I could compile and run my form, but I am not getting the events from the
> ActiveX control. The code looks like this:
>
> public void KeyPressOnCtrl(object sender,
> AxActiveXCtrlALib._DActiveXCtrlAEvents_KeyPressEvent e)
> {
> MessageBox.Show("Event from activeX control received");
> }
>
> public Form1()
> {
> InitializeComponent();
> this.axActiveXCtrlA1.KeyPressEvent +=
> new
> AxActiveXCtrlALib._DActiveXCtrlAEvents_KeyPressEventHandler
> (this.KeyPressOnCtrl);
>
> }
>
> Am I missing something here? Any help is greatly appreciated.
>
> Thanks a lot,
> Jessy