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++ / May 2007

Tip: Looking for answers? Try searching our database.

Fire KeyDown in C++

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
T - 14 May 2007 16:50 GMT
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 - 14 May 2007 17:10 GMT
> Hi,
>
[quoted text clipped - 4 lines]
> 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;
SvenC - 14 May 2007 17:28 GMT
Hi T,

>> Hi,
>>
[quoted text clipped - 9 lines]
> 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.

--
SvenC
T - 14 May 2007 18:24 GMT
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;
        }
    };
}
[/code]
Ben Voigt - 14 May 2007 19:18 GMT
> Hi T,
>
[quoted text clipped - 15 lines]
> 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.

> --
> SvenC
SvenC - 14 May 2007 17:12 GMT
Hi 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.

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

--
SvenC

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.