Hello,
First I would recommend you read about delegates, a good start is MSDN:
http://msdn.microsoft.com/en-us/library/orm-9780596521066-01-17.aspx[
^]
Anyway here is a way to do it using delegates:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
static void Loader(PictureBox pict)
{
Bitmap bmp = (Bitmap)Image.FromFile("c:\\test.jpg");
pict.Image = bmp;
}
void button1_Click(object sender, EventArgs e)
{
LoadBmpHelper myLoader = new LoadBmpHelper();
LoadBmpHelper.PictureHandler loader = new LoadBmpHelper.PictureHandler(Loader);
myLoader.LoadBmp(loader, pictureBox1);
}
}
public class LoadBmpHelper
{
public delegate void PictureHandler(PictureBox pict);
public void LoadBmp(PictureHandler pictureHandler, PictureBox pict)
{
if (pictureHandler != null)
{
pictureHandler(pict);
}
}
}
A delegate is a reference to a method, basically you declare a method signature. When you use the class that contains the delegate you pass it your own method that matches the signature. It's basically an easy way to decouple class.
Valery.