Fire KeyDown in C++

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
 
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

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;
 
S

SvenC

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.
 
S

SvenC

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.
 
T

T

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;
}
};
}
 
B

Ben Voigt

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top