Professional IronPython


Interacting with Predefined and Custom Events



Download 20,35 Mb.
Pdf ko'rish
bet170/453
Sana01.07.2022
Hajmi20,35 Mb.
#723045
1   ...   166   167   168   169   170   171   172   173   ...   453
Interacting with Predefined and Custom Events
 

 
155
Likewise, 
Remove()
takes the requested event handler reference out of the container using the 
self.HandlerList.remove()
method. Because someone could pass an invalid reference, the code 
must perform this task within a 
try...except
block, capturing the 
KeyError
exception as needed. 
The 
pass
keyword tells IronPython not to do anything about the exception. Normally, you’d pro-
vide some type of error handling code.
Invoking (firing) the event is the responsibility of the 
Fire()
method. This event accepts a message, 
Msg
, and does something with it. Precisely what happens with 
Msg
is up to the event handler. All the 
event knows is that it must accept a 
Msg
object and pass it along to the event handler. As you can 
see, the code calls each event handler reference in turn and passes the 
Msg
to it. In short, the event 
handler must have the proper signature (set of input arguments) to handle the event correctly.
It’s important to realize that event handlers may not receive calls in the order in 
which you add them to the event. Consequently, you should never create event 
handlers that depend on a specific order of calling.
Devising an Event Class Test Form
Now that you have a new event, you’ll want to do something with it. Listing 8-6 shows code used to 
create the form for this example.
lISTINg 8-6: 
 Creating an event class test form
# Set up the path to the .NET Framework. 
import sys
sys.path.append(‘C:\\WINDOWS\\Microsoft.NET\\Framework\\v2.0.50727’)
# Make clr accessible.
import clr
# Add any required references.
clr.AddReference(‘System.Windows.Forms.DLL’)
clr.AddReference(‘System.Drawing.DLL’)
# Import the .NET assemblies.
import System 
import System.Windows.Forms
import System.Drawing.Point
class frmMain(System.Windows.Forms.Form):
# This function performs all of the required initialization.
def InitializeComponent(self):
# Configure the form.
self.ClientSize = System.Drawing.Size(350, 200)
self.Text = ‘Creating an Event Example’
continues
548592c08.indd 155
2/24/10 12:48:12 PM
www.finebook.ir



Download 20,35 Mb.

Do'stlaringiz bilan baham:
1   ...   166   167   168   169   170   171   172   173   ...   453




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