Error changing Icon for ErrorProvider

E

Eric

I am attempting to change at runtime the Icon for an ErrorProvider.
When I do so and call SetError(thisControl, "msg") I receive an
IndexOutOfRangeException.

Code snippet:
....
Assembly _assembly = Assembly.GetExecutingAssembly();
Stream _icon =
_assembly.GetManifestResourceStream("MyNameSpace.checkmark.ico");
thisErrorProvider.Icon = new Icon(_icon);
thisErrorProvider.SetError(thisControl, "Checked");
....

To cover the obvious, yes, the Build Action Property of checkmark.ico
is Embedded Resource.

Here is the exception stacktrace:
System.IndexOutOfRangeException was unhandled
Message="Index was outside the bounds of the array."
Source="System.Windows.Forms"
StackTrace:
at System.Windows.Forms.ErrorProvider.IconRegion.get_Region()
at
System.Windows.Forms.ErrorProvider.ErrorWindow.Update(Boolean
timerCaused)
at
System.Windows.Forms.ErrorProvider.ErrorWindow.Add(ControlItem item)
at System.Windows.Forms.ErrorProvider.ControlItem.AddToWindow()
at
System.Windows.Forms.ErrorProvider.ControlItem.set_Error(String value)
at System.Windows.Forms.ErrorProvider.SetError(Control control,
String value)
....

I'm digging through msdn now. Any advice is appreciated.

Many Thanks,
Eric
 
E

Eric

For anyone interested, I found the problem. The default icon is 16x16
pixels, but checkmark.ico was 14x14. Recreating the checkmark.ico at
16x16 resolved the problem.

Cheers.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top