VB.NET ©e¬£(Delegate) ¨Æ¥ó(Event)
- ©«¤l
- 20
- ¥DÃD
- 18
- ºëµØ
- 0
- ¿n¤À
- 43
- ÂI¦W
- 0
- §@·~¨t²Î
- windows xp
- ³nÅ骩¥»
- Office 2003
- ¾\ŪÅv
- 10
- ©Ê§O
- ¨k
- µù¥U®É¶¡
- 2011-9-5
- ³Ì«áµn¿ý
- 2011-9-6
|
VB.NET ©e¬£(Delegate) ¨Æ¥ó(Event)
©e¬£(Delegate)
©w¸q Method µ²ºc
©w¸q
'©w¸q©e¬£
2 Public Delegate Sub sayHello(ByVal thing As String)
¥Dµ{¦¡
view sourceprint?01 Imports mod08
02
03 Module TestHelloWorldDelegate
04 Public Sub Main()
05 '«Øºc©e¬£
06 Dim handler As New sayHello(AddressOf engHelloWorld)
07 '©I³ê(³ê¿ô)-¦P¨B
08 handler.Invoke("eric")
09 End Sub
10
11 'µ¹©e¬£¥Îªºµ{§Ç
12 Private Sub engHelloWorld(ByVal s As String)
13 System.Console.WriteLine(s + " Hello World!!!")
14 End Sub
15 End Module
Ãþ§O¼h¯Å
¥Dµ{¦¡ À³¥Îµ{¦¡¼h¯Å (Event)
view sourceprint?01 Public Class HelloWorld
02 'Data field
03 Private _msg As String
04 '¨Æ¥ó
05 Public Event myhandler As sayHello
06 'ÄÝ©Ê
07 Public Property Msg() As String
08 Get
09 Return Me._msg
10 End Get
11 Set(ByVal value As String)
12 Me._msg = value
13 End Set
14 End Property
15
16 '¤Þµo¨Æ¥óªº method
17 Public Sub Rasing(ByVal s As String)
18 '¤Þµo¨Æ¥ó->²o¯A¨ìÀ³¥Î¨t²Î©Ò¼gªº¨Æ¥óµ{§Ç(???)
19 RaiseEvent myhandler(s)
20 End Sub
21 End Class
view sourceprint?01 Module TestClassEvent
02
03 Public Sub Main()
04 '«Øºcª«¥ó
05 Dim hello As New HelloWorld()
06 '«Ø¥ß¨Æ¥óµ{§Ç
07 'ºÞ²zû«Ø¥ß
08 Dim handler As New sayHello(AddressOf HelloWorld)
09 'Å¥ª«¥óªº¨Æ¥ó
10 AddHandler hello.myhandler, handler
11 '¤Þµo
12 hello.Rasing("eric")
13 End Sub
14
15 '¨Æ¥óµ{§Ç
16 Private Sub HelloWorld(ByVal s As String)
17 System.Console.WriteLine(s + " ¥@¬É©M¥!!")
18 End Sub
19 End Module
mod08.rar |
|
Ó¤Hñ¦W@
|
|
|
|
|
- ©«¤l
- 5
- ¥DÃD
- 0
- ºëµØ
- 0
- ¿n¤À
- 5
- ÂI¦W
- 0
- §@·~¨t²Î
- win7
- ³nÅ骩¥»
- 7
- ¾\ŪÅv
- 10
- µù¥U®É¶¡
- 2012-11-27
- ³Ì«áµn¿ý
- 2012-11-27
|
¦]¬°¬Oè¤Jªù¾Ç¼gµ{¦¡¡A¤£¤Ó²M·¡©e¬£©M¨Æ¥óªº¨Ï¥Î®É¾÷¡A¤£ª¾¹D¬O§_¥i¥H«ü¾É¤@¤U¤GªÌ¨Ï¥Îªº®t§O? |
|
|
|
|
|
|