Developer Programmer
چهارشنبه 30 بهمن 1387, 14:42 عصر
وقتی که داریم یه کلاس مثل TShape مینویسیم. چطور میتونیم یک متد رو از نوع Event تعریف کنیم؟ تا بعد اون رو هندل کنیم؟
Ali_Mor
چهارشنبه 30 بهمن 1387, 16:21 عصر
فرض کنیم می خوای در پایان عملیات Load یک اونت رخ بده
public class TShape
{
public event CopmpleteEventHandler Copmplete;
public delegate void CopmpleteEventHandler();
public void load()
{
//...
//...
//...
if (Copmplete != null) {
Copmplete();
}
}
}
حالا در برنامه اینجوری ازش استفاده کن
private void Form1_Load(object sender, EventArgs e)
{
TShape test = new TShape();
test.Copmplete += Complete_Handel;
test.load();
}
private void Complete_Handel()
{
MessageBox.Show ("load complete ");
}
vBulletin® v4.2.5, Copyright ©2000-1403, Jelsoft Enterprises Ltd.