Ask general questions about the .NET Framework. Discuss general CTS, CLR, and other .NET Platform questions and issues
Question about Events & delegates...
I'm quite new in .Net technologies and I have a question about the Events for Windows::Forms::Control According to the .Net Framework developer Center, the fellowing list are personalized Events for Control : AutoSizeChanged BackColorChanged BackgroundImageChanged BackgroundImageLayoutChanged Click ..... .... Am'I right If I say that they are methods pointers and a Control have many methods pointers than events? thanks, Michel.
Delegates are in general Functions/Methods pointers. A control raises many events (like the ones on your list). When you implement an event handler for a defined control event you need to link that event handler (which is a function) to the event through a delegate like this: Code: button.Click += new EventHandler(this.Button_Clicked); When button is the name of the control, Click is the event and Button_Clicked is the name of your method. EventHandler is a generic delegate (System.EventHandler). This code is written automatically in C# when you for example double click on a button on a designer. In VB you got a syntax like Handles.button.Click right after the declaration line (the first line) of your function.
Thanks you for your reply, but the thing I want to know "Type" is event Click? What is an "event Click"? because we can do semothing like this : button.Click += new EventHandler(this.Button_Clicked); I guest that Click is a kind of array of functions/methods pointers. Perharps I'm not clear... I'm not a natif english speaker Michel.
Event is not a type, is just a keyword. quoting from MSDN: "The event keyword lets you specify a delegate that will be called upon the occurrence of some "event" in your code. The delegate can have one or more associated methods that will be called when your code indicates that the event has occurred. " You can specify your own events, but in order to specify events and handle them you should: Code: //1) declare a delegate: public delegate void myEventHandler(object sender, AlarmEventArgs e); //2) "declare" an event on your delegate //(read the first sentence from the quote now): public event myEventHandler myEvent; //3)Wire event and SomeMethod through the event delegate //(At some initialization stage) myControl.myEvent += new myEventHandler(SomeMethod); You can do this without explictly declaring a delegate and event if you are using .NET built in controls, because they already have their own events and delegates (EventHandler - which uses a generic System.EventHandler delegate) declared, as shown in the previous post, so you can just wire an event to SomeMethod using the generic delegate called EventHandler. Sorry it is not clear enough, but if you go through some tutorials you'll start catching these sometimes confusing concepts. Hope it might Help! JI