Invoke

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?
[559 byte] By [skuehner] at [2007-11-19 19:31:03]
# 1 Re: Invoke
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 ;-)
skuehner at 2007-11-9 12:39:31 >