zoukankan
html css js c++ java
简单的委托事件
class
1
using
System;
2
using
System.Collections.Generic;
3
4
namespace
ConsoleApplication3
5
{
6
/**/
///
<summary>
7
///
事件接受类
8
///
</summary>
9
class
Program
10
{
11
static
void
Main(
string
[] args)
12
{
13
EventSend es
=
new
EventSend();
14
es.myEvent
+=
new
EventSend.myDelegate(es_myEvent);
15
es.Run();
16
}
17
18
private
static
void
es_myEvent(
object
sender,MyEventArgs e)
19
{
20
//
事件处理方法
21
Console.WriteLine(
"
\n你触发了一次事件!\n你输入的是:
"
+
e.InputText);
22
}
23
}
24
/**/
///
<summary>
25
///
事件发送类
26
///
</summary>
27
class
EventSend
28
{
29
public
delegate
void
myDelegate(
object
sender, MyEventArgs e);
//
定义委托
30
public
event
myDelegate myEvent;
//
定义委托类型的事件
31
public
void
Run()
32
{
33
while
(
true
)
34
{
35
Console.BackgroundColor
=
ConsoleColor.Red;
36
Console.ForegroundColor
=
ConsoleColor.Yellow;
37
Console.WriteLine(
"
=== 退出请选择 n 或 N ===
"
);
38
MyEventArgs e1
=
new
MyEventArgs();
39
e1.InputText
=
Console.ReadLine();
40
string
str
=
e1.InputText;
41
if
(str
==
"
n
"
||
str
==
"
N
"
)
42
{
43
break
;
44
}
45
myEvent(
this
, e1);
46
}
47
}
48
}
49
50
/**/
///
<summary>
51
///
事件的内容
52
///
</summary>
53
class
MyEventArgs:EventArgs
54
{
55
private
string
inputText;
56
public
string
InputText
57
{
58
get
59
{
60
return
this
.inputText;
61
}
62
set
63
{
64
this
.inputText
=
value;
65
}
66
}
67
}
68
}
69
每天进步一点点...
查看全文
相关阅读:
属性的自动完成
二十七、详测 Generics Collections TDictionary(3): TPairEnumerator、TKeyEnumerator、TValueEnumerator、ExtractPair
Delphi 反转内存的函数
类方法调用
九、泛型排序器 TComparer
十九、详测 Generics Collections TList (10): OnNotify 事件
二十、详测 Generics Collections TList (11): Create
二十一、详测 Generics Collections TQueue (1): Enqueue、Dequeue、Peek
十四、详测 Generics Collections TList (5): Move、Exchange
二十二、详测 Generics Collections TQueue (2): Create、Count、Clear、TrimExcess
原文地址:https://www.cnblogs.com/cyan/p/1287381.html
最新文章
wcf基础知识之完结
wcf基础知识之ListenUri和ListenUriMode实现 逻辑地址和物理地址的分离
契约操作不能使用引用对象作为参数,只允许使用基本类型或数据契约
二十三、详测 Generics Collections TQueue (3): OnNotify、Extract
十七、详测 Generics Collections TList (8): Sort
十二、详测 Generics Collections TList (3): Insert、Delete、Remove、Extract
类: property
八、使用泛型的 TArray 从动态数组中查找指定元素
类成员可见性
继承窗体
热门文章
(转)DELPHI大内存清零快速算法(Delphi MMX优化算法应用之二)
抽象类
覆盖虚方法
方法重载
十三、详测 Generics Collections TList (4): AddRange、InsertRange、DeleteRange
参数默认值
十一、详测 Generics Collections TList (2): First、Last、IndexOf、LastIndexOf
三十、详测 Generics Collections: TObjectList、TObjectQueue、TObjectStack
十六、详测 Generics Collections TList (7): Items、Contains
七、使用泛型的 TArray 为动态数组排序
Copyright © 2011-2022 走看看