First, I assume you didn't spell 'void' with a capital 'V'. The 2nd
statement you said doesn't work uses the keyword 'this' twice. In the first
case, it is what the KeyDown event handler is being added to. In the second
case, it's where the handler is located. Therefore, your code will only work
if:
(1) Both of your code lines are included in the same class definition.
(2) The class they are both defined in MUST be DERIVED from the Control*
class (based on the handlers name, probably Form*).
The reason for (1) is so that both of the 'this''s refer to the same thing
(which they obviously must), and (2) is because you can only add a KeyDown
handler to a Control* (or a derived class).
If (2) is NOT the case, it must be that some member of the class is a
Control* that should be given the handler, let's call it My_Control (a
pointer to the Control*). Then:
this->My_Control->KeyDown += new KeyEventHandler( this, Form1_KeyDown) ;
should work.
[==Peteroid==]
> I have function :
> System::Void Form1_KeyDown(Object* sender, KeyEventArgs* e)
[quoted text clipped - 5 lines]
> how I can change it to run?
> please help
Steve McLellan - 04 Mar 2005 16:23 GMT
To be pedantic, System::Void (with caps 'V') is correct. The rest of the
answer is spot on though :-)
> First, I assume you didn't spell 'void' with a capital 'V'. The 2nd
> statement you said doesn't work uses the keyword 'this' twice. In the
[quoted text clipped - 29 lines]
>> how I can change it to run?
>> please help
Peteroid - 04 Mar 2005 18:24 GMT
Yeah, I wondered about that ('V'oid), and realized later it might have been
correct. I have only ever used 'void' myself, and never knew this other form
(System::Void ) worked as well. But you learn something every day! :)
[==Peteroid==]
> To be pedantic, System::Void (with caps 'V') is correct. The rest of the
> answer is spot on though :-)
[quoted text clipped - 32 lines]
>>> how I can change it to run?
>>> please help