I have a Form class:

public partial class Capture : Form
{    

    private DisplayError _displayError;

    public Capture(DisplayError displayError)
    {
        _displayError = displayError;
    }

    private OtherMethod()
    {
        _displayError("string with error");
    }
}

And DisplayError class (both are in the same namespace):

public class DisplayError
{
    public DialogResult ShowErrorBox(string error)
    {
        return MessageBox.Show(error, "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
    }
}

I have an error

There is no argument given that corresponds to the required formal parameter 'displayError' of 'Capture.Capture(DisplayError)'

on line Application.Run(new Capture());

How'd I load DisplayError instance as Capture parameter?

5 upvote
  flag
With another new? – Adriano Repetti
1 upvote
  flag
Did Application.Run(new Capture(new DisplayError())); work? – dasblinkenlight

1 Answers 11

up vote 1 down vote accepted

Not sure why this is a question, but the constructor is for parameters that are required when the form instance is created. So when newing up an instance you need to pass the parameter.

Application.Run(new Capture(new DisplayError()));

Not the answer you're looking for? Browse other questions tagged or ask your own question.