Using system;
Using system. Collections. Generic;
Using system. componentmodel;
Using system. drawing;
Using system. Data;
Using system. text;
Using system. Windows. forms;
Using system. IO;
/// <Summary>
/// Custom Thumbnail Control
/// </Summary>
Public class ctlpicturebox
{
Public Delegate void picclickhandler (Object sender, pictureargs E );
/// <Summary>
/// Define a click event
/// </Summary>
Public event picclickhandler picclick;
Protected virtual void onpictureclick (pictureargs E)
{// Event trigger Method
If (picclick! = NULL)
{// Determine whether the event is empty
Picclick (this, e); // trigger the event
}
}
// Trigger event
Private void pbimg_click (Object sender, eventargs E)
{
Pictureargs ARGs = new pictureargs ();
Args. filename = filename;
Onpictureclick (ARGs );
}
}
Public class pictureargs: eventargs
{
Private string filename = "";
/// <Summary>
/// File name
/// </Summary>
Public String filename
{
Get {return filename ;}
Set {filename = value ;}
}
}
Example 2
Using system;
Using system. Collections. Generic;
Using system. componentmodel;
Using system. drawing;
Using system. Data;
Using system. LINQ;
Using system. text;
Using system. Windows. forms;
Namespace Test
{
Public partial class mycontrol: usercontrol
{
Public mycontrol ()
{
Initializecomponent ();
}
Public Delegate int mydelegate (string Str );
Public mydelegate clickhandler = NULL;
Private void button#click (Object sender, eventargs E)
{
If (clickhandler! = NULL)
{
Clickhandler ("hello ");
}
}
}
}
Call Method
Public int test (string Str)
{
MessageBox. Show (STR );
Return 1;
}
Public int test1 (string Str)
{
MessageBox. Show (STR + "," + Str );
Return 1;
}
Private void form1_load (Object sender, eventargs E)
{
Mycontrol1.clickhandler + = test;
Mycontrol1.clickhandler + = test1;
// Mycontrol1.clickhandler-= test1;
}