I have a few buttons and I use custom images for hover, pushed, etc.
I also have images for the disabled state. The problem is that when I change enabled to false, my EnabledChanged event fires and tries to change the image and also an internal event is fired that tries to desaturate the curent foreground and something very
wrong happens and I get an out of memory exception.
How can I stop it from desaturating the image and leave me do the job ?
-
-
How do you draw the images on the buttons?
-
It doesn't matter anymore. It was a stupid homework which I finished from 4 to 5 am in the morning before the deadline
I had something like:Image buttonPlayDisabled;If I don't change the image on EnabledChanged event, by default, a desaturated version of the image already on my button is put in place. And it looks kind of ugly. Is there a way to disable this behavior ? I don't really care so much now, but just out of curiosity
bool loaded=true;
...
Assembly assembly = Assembly.GetExecutingAssembly();
Stream stream = assembly.GetManifestResourceStream("MyProject.bitmaps.buttonPlayDisabled.jpg");
if (stream != null)
{
buttonPlayDisabled = Image.FromStream(stream);
}
stream.Close();
if(buttonPlayDisabled == null)
loaded=false;
...
private void playButton_EnabledChanged(object sender, EventArgs e)
{
if (!loaded)
return;
if (playButton.Enabled)
{
playButton.Image = buttonPlayOriginal;
}
else
{
playButton.Image = buttonPlayDisabled;
}
}
-
Probably you need to write your own button class to do it...
-
I would have overridden the ondrawbackground method.
Thread Closed
This thread is kinda stale and has been closed but if you'd like to continue the conversation, please create a new thread in our Forums,
or Contact Us and let us know.