1namespace EventEmail
2{
3 /**//// <summary>
4 /// 手機
5 /// </summary>
6 public class CallPhone
7 {
8 private TextBox _tBox;
9 public CallPhone(MailManager mm, TextBox tBox)
10 {
11 mm.MailMsg += new MailMsgEventHandler(CellPhoneMsg);
12 _tBox = tBox;
13 }
14
15 private void CellPhoneMsg(Object sender, MailMsgEventArgs e)
16 {
17 _tBox.Text += string.Format("消息到手機:{4}來自:{0}{4}發到:{1}{4}主題:{2} {4}內容:{3}{4}{4}", e.from, e.to, e.subject, e.body,Environment.NewLine);
18 }
19
20 public void Register(MailManager mm)
21 {
22 mm.MailMsg += new MailMsgEventHandler(CellPhoneMsg);
23 }
24 public void UnRegister(MailManager mm)
25 {
26 mm.MailMsg -= new MailMsgEventHandler(CellPhoneMsg);
27 }
28 }
29}
四.客戶端調用
上面的邏輯處理完畢,下面來看看調用情況:
1namespace EventEmail
2{
3 public partial class Form1 : Form
4 {
5 private Fax fax = null;
6 private CallPhone cell = null;
7 private MailManager mm = null;
8 public Form1()
9 {
10 InitializeComponent();
11 mm = new MailManager();
12 fax = new Fax(mm, txtReceiver);
13 cell = new CallPhone(mm, txtReceiver);
14 }
15
16 private void Form1_Load(object sender, EventArgs e)
17 {
18
19 }
20
21 private void btnSend_Click(object sender, EventArgs e)
22 {
23 mm.SimulateArrivingMsg(txtFrom.Text, txtTo.Text, txtSubject.Text, txtBody.Text);
24 }
25
26 private void btnClear_Click(object sender, EventArgs e)
27 {
28 this.txtReceiver.Text = "";
29 }
30 }
31}