Stéphane Gourichon
Stéphane Gourichon

Reputation: 7021

Windows Forms: prevent ActiveX from getting mouse events

Context

In a C# Windows Forms application for Win7 we host an ActiveX control. So far, so good.

Need: prevent ActiveX to receive mouse events

Actually, the ActiveX has too much functionality. It is not very customizable to turn off features we don't need.

It would be nice if we just prevented it from receiving mouse events.

The ideal would be to just treat events as if the ActiveX was not there, that is the mouse clicks go right through to the underlying (or containing) Control.

But if we just prevent the ActiveX from getting events that would be okay with us.

Search before you ask

Some answers to previous questions mention to protected override void WndProc(ref Message m), e.g. c# - Pass-through mouse events to parent control - Stack Overflow

Other mentions to implement IMessageFilters, e.g.:

Experiment: ActiveX still gets events

I have fairly extensively tried both override WndProc and IMessageFilter ways, filtering (opt-in and opt-out) a number of events. In some cases I can prevent events to reach native C# controls, but the ActiveX still got its share.

Filtering too much, prevented controls and ActiveX to paint, or even application to draw properly or caused crash on exit. This can be averted by selecting opt-in or opt-out options carefully.

Is there another way?

Is there another way from C#/.NET to host an ActiveX Control while preventing it from getting mouse events? Perhaps at application start time?

Upvotes: 2

Views: 923

Answers (2)

Stéphane Gourichon
Stéphane Gourichon

Reputation: 7021

I just faced the same issue (with a different ActiveX).

@GunnarRoth's answer and the page Using Window Handle to disable Mouse clicks using c# - Stack Overflow imply platform-specific magic with window handle, which is better avoided when possible.

A hint, still, is that it has Enabled in its name.

The ActiveX host object is a Windows Forms Control. I just set Enabled=false and the effect is exactly what I want : no mouse clicks or keyboard events are seen by the ActiveX, yet it still displays fine.

I don't even know if this would answer my initial question with the initial ActiveX Control, but this time it does! :-)

Upvotes: 1

Gunnar Roth
Gunnar Roth

Reputation: 1

Try to do a EnableWindow(hand,FALSE) on the uppermost hwnd of the ActiveX Control after has been created. See Using Window Handle to disable Mouse clicks using c# how to do this in c#.

Upvotes: 0

Related Questions