C# 0 The Complete Reference


MyEventArgs  is derived from  EventArgs



Download 4,07 Mb.
Pdf ko'rish
bet547/1096
Sana23.01.2022
Hajmi4,07 Mb.
#402171
1   ...   543   544   545   546   547   548   549   550   ...   1096
Bog'liq
C-Sharp 3 The Complete Reference Herbert Schildt

MyEventArgs

 is derived from 



EventArgs

.

MyEventArgs

 adds just one 

field of its own: 



EventNum

. The event handler delegate 



MyEventHandler

 now takes the 

two parameters required by the .NET Framework. As explained, the first is an object 

reference to the generator of the event. The second is a reference to 



EventArgs

 or a class 

derived from 

EventArgs

. The event handlers in the 



X

 and 


Y

 classes, 



Handler( )

, also have 

the same types of parameters.

Inside


MyEvent

, a 


MyEventHandler

 called 


SomeEvent

 is declared. In the 



OnSomeEvent( ) 

method,


SomeEvent

 is called with the first argument being 



this

, and the second argument 

being a 

MyEventArgs

 instance. Thus, the proper arguments are passed to 



MyEventHandler

to fulfill the requirements for .NET compatibility.



Use EventHandler

For many events, the 



EventArgs

 parameter is unused. To help facilitate the creation of code in 

these situations, the .NET Framework includes a built-in delegate type called 

EventHandler

,

which can be used to declare event handlers in which no extra information is needed. Here 



is an example that uses 

EventHandler

:

// Use the built-in EventHandler delegate.



using System;

// Declare a class that contains an event.

class MyEvent {

  public event EventHandler SomeEvent; // uses EventHandler delegate

  // This is called to fire SomeEvent.

  public void OnSomeEvent() {

    if(SomeEvent != null)

      SomeEvent(this, EventArgs.Empty);

  }

}

class EventDemo7 {



  static void Handler(object source, EventArgs arg) {

    Console.WriteLine("Event occurred");

    Console.WriteLine("Source is " + source);

  }


www.freepdf-books.com


Download 4,07 Mb.

Do'stlaringiz bilan baham:
1   ...   543   544   545   546   547   548   549   550   ...   1096




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish