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 / Languages / Managed C++ / March 2005

Tip: Looking for answers? Try searching our database.

keydown event

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Peter S - 01 Mar 2005 13:25 GMT
I have function :
System::Void Form1_KeyDown(Object* sender, KeyEventArgs* e)

but this:
this->KeyDown += new KeyEventHandler(this, Form1_KeyDown);

doesnt work..
how I can change it to run?
please help
           
Peteroid - 03 Mar 2005 17:54 GMT
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

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.