Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Interop / March 2007

Tip: Looking for answers? Try searching our database.

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

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Jessica - 19 Mar 2007 05:42 GMT
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
Dick Swager - 21 Mar 2007 01:15 GMT
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

> Hi All,
>
[quoted text clipped - 36 lines]
> Thanks a lot,
> Jessy

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.