Dear George,
Based on my understanding, you're using a ToolBar control(.NET 1.x ), the
ToolBarButton shows an image when it is enabled, but when the ToolBarButton
is disabled, the image is not displayed.
As far as I know this is a by design feature with the old ToolBar
control(.NET 1.x), you can refer to this document:
ToolBarButton.Enable Property
http://msdn.microsoft.com/en-us/library/system.windows.forms.toolbarbutton.e
nabled.aspx
It says:
[MSDN]
If the image or text has multiple colors, they display in a monochromatic
gray.
[/MSDN]
So, if the image you used is colorful, when a ToolBarButton is disabled, a
monochromatic gray would be displayed on it, resulting the disappear of the
image.
For .NET 2.0 and above, there's a new control named "ToolStrip", which can
show a nice gray image when the ToolStripButton is disabled. If you're
working on Visual Studio 2005/2008, I would recommend you use this
ToolStrip control instead.
However, if you're using Visual Studio 2003, you can try my resolution
below to show a gray image on the ToolBarButton when it is disabled,
Sample code for your information:
public class ToolBarEx : ToolBar
{
protected override void WndProc(ref Message m)
{
base.WndProc(ref m);
if (m.Msg == 0x000F) //WM_PAINT
{
foreach (ToolBarButton b in this.Buttons)
{
if (!b.Enabled)
{
using (Graphics g = this.CreateGraphics())
{
Bitmap bmp =
this.GetGrayImage(this.ImageList.Images[b.ImageIndex]);
g.DrawImage(bmp, b.Rectangle.X + 4,
b.Rectangle.Y + 3);
}
}
}
}
}
private Bitmap GetGrayImage(Image ImgSource)
{
Bitmap bmp = new Bitmap(ImgSource.Width, ImgSource.Height);
Bitmap img = ImgSource as Bitmap;
for (int h = 0; h < bmp.Height; h++)
{
for (int w = 0; w < bmp.Width; w++)
{
Color c = img.GetPixel(w, h);
Color newColor = Color.FromArgb(
(int)(0.5 * c.R + 0.3 * c.G + 0.2 * c.B),
(int)(0.5 * c.R + 0.3 * c.G + 0.2 * c.B),
(int)(0.5 * c.R + 0.3 * c.G + 0.2 * c.B));
bmp.SetPixel(w, h, newColor);
}
}
return bmp;
}
}
If anything is unclear, please don't hesitate to let me know. I'm glad to
be of assistance.
Sincerely,
Zhi-Xin Ye
Microsoft Managed Newsgroup Support Team
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subscriptions/aa948868.aspx#notifications.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://support.microsoft.com/select/default.aspx?target=assistance&ln=en-us.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.