Hi Scorgi,
You said
Currently it will just leave a transparent space on the toolstripbutton.It is because if a image does not exist, it would return null. In other words, the bitmap buttonA would be null.
From my experience, there are three ways to cope with such a case:
1. Throw an exception.
2. Show a message.
3. Bind a default bitmap to the button.
This is the code snippet:
Bitmap map = (Bitmap)Properties.Resources.ResourceManager.GetObject("mybuttonA");
if (map == null)
{
string msg = "The image mybuttonA cannot be found!";
//1. Throw an exception.
throw new ArgumentException(msg);
//2. Show a message.
MessageBox.Show(msg);
//3. Bind a default bitmap to the button.
map = (Bitmap)Properties.Resources.ResourceManager.GetObject("default");
}
Let me know if this does not help.
Aland Li
Please mark the replies as answers if they help and unmark if they don't. This can be beneficial to other community members reading the thread.