Click to See Complete Forum and Search --> : Invoke


skuehner
March 10th, 2006, 12:43 PM
Hello,

I defined the following delegate:


public delegate void FormOpenFunction();


Then I call the following function:


Form tmpForm;

public void OpenForm(Form form)
{
tmpForm = form;

FormOpenFunction formOpenFunction=new FormOpenFunction(FormOpener);

Invoke(formOpenFunction);
}

public void FormOpener()
{
tmpForm.ShowDialog();
}


When I want to compile it, there appears an System.ArgumentException in the line "Invoke(...)".

What is wrong?

skuehner
March 10th, 2006, 02:32 PM
Hi!

I've the solution (if someone wants to know it):

The delegate has to be EventHandler:


Invoke(new EventHandler(DelegateFunction));

... and so the function has the be of the following form:

public void DelegateFunction(object sender, System.EventArgs e)
{
// Open Form or whatever you want...
}

Obviously it doesn't matter if you don't use the parameters ;-)