Fire KeyDown in C++

  • Thread starter Thread starter T
  • Start date Start date
T

T

Hi,

How do I fire the KeyDown event in Managed VC++? I am getting a
compile error saying "event does not have a raise method". Please
help.


regards,
T
 
Hi,

How do I fire the KeyDown event in Managed VC++? I am getting a
compile error saying "event does not have a raise method". Please
help.

regards,
T

I managed to fix this though I don't know why the compile failed. I
was trying to fire the event in a class derived from Panel. The fix is
to redeclare the event as:
__event KeyEventHandler *KeyDown;
 
Hi T,

T said:
Hi,

How do I fire the KeyDown event in Managed VC++? I am getting a
compile error saying "event does not have a raise method". Please
help.

Please show us the code you have so far and show the line in error.
 
Hi T,

T said:
I managed to fix this though I don't know why the compile failed. I
was trying to fire the event in a class derived from Panel. The fix is
to redeclare the event as:
__event KeyEventHandler *KeyDown;

As far as I know managed classes inherit public by default in contrast to
native C++. So did you explicitly inherit private from Panel? Alternatively
you could try to explicitly inherit with "public Panel"

Otherwise this could indicate a compiler bug.
 
Hi SvenC,

Here is the code:
Code:
namespace NuDesign {
using namespace System::Windows::Forms;

public __gc class ndPanel : public System::Windows::Forms::Panel {
public:
__event KeyEventHandler *KeyDown;

virtual bool ProcessCmdKey(Message __gc *msg, Keys key){
if(msg->Msg == 0x100 && (key == Keys::Up || key == Keys::Down ||
key == Keys::Left
|| key == Keys::Right)){
KeyDown(0, new KeyEventArgs(key));
}
return false;
}
};
}
 
SvenC said:
Hi T,



As far as I know managed classes inherit public by default in contrast to
native C++. So did you explicitly inherit private from Panel?
Alternatively you could try to explicitly inherit with "public Panel"

..NET doesn't allow private inheritance.
Otherwise this could indicate a compiler bug.

No, it's the same in C# and VC++ 2005. Only the class which declares an
event can fire it. The public access refers to the ability to subscribe
handlers, not to trigger the event. Usually calling the base class has an
OnKeyDown method which you can call, resulting in the event being fired with
your parameters.

Or, you can hide the parent event as you've done, but anyone who subscribes
with a base class pointer won't see your event.
 
Back
Top