I am trying to change the icon of errorProvider in Windowsform. I have added .ico files in Properties->Resources folder. I have tried directly copy pasting the .ico file, have also used the Add resources->Add Existing Files option. What ever I do, if I add my own .ico file and try to set them as errorProvider icon as show in the code below, I get an exception while running the program (particularly when trying to demonstrate the the errorProvider feature in my program). My code is:
private void textBox1_Leave(object sender, EventArgs e)
{
if(string.IsNullOrEmpty(textBox1.Text))
{
textBox1.Focus();
errorProvider1.Icon = Properties.Resources.cross; //here I have change the default icon
errorProvider1.SetError(this.textBox1, "Input UserId"); //having exception in this line
}
else
{
errorProvider1.Icon = Properties.Resources.right;
}
}

The exception details:
System.StackOverflowException
HResult=0x800703E9
Source=<Cannot evaluate the exception source>
StackTrace:
<Cannot evaluate the exception stack trace>


Adding resources through
Resource.resxcan also refer to ico very well.Copy if newis another calling method.Add existing resources:
It might be better to change the
leaveevent to theValidatingevent.I have tested your code itself and there is no problem.
I have
reproduced the errorhere because it is caused by theico file itself.It can be solved by changing a picture.
The error document is here.
You can use a file converter to convert to ico.
Output: