I found the ControlPaint class... however i'm now wondering:
Would this be bad? I'm not sure if it's going to leak memory or not -
can I get some feedback? thanks :)
if (this._icon != null)
{
if (this.Text != "" && this.Text != "X")
{
if (this.Enabled)
e.Graphics.DrawIcon(this._icon, e.Bounds.Left+ICON_PAD_LEFT,
e.Bounds.Top+ICON_PAD_TOP);
else
ControlPaint.DrawImageDisabled(e.Graphics, this._icon.ToBitmap(),
e.Bounds.Left+ICON_PAD_LEFT, e.Bounds.Top+ICON_PAD_TOP, br.Color);
}
else
{
// center icon:
if (this.Enabled)
e.Graphics.DrawIcon(this._icon, e.Bounds.Left +
((e.Bounds.Width - this._icon.Width) / 2), e.Bounds.Top+ICON_PAD_TOP);
else
ControlPaint.DrawImageDisabled(e.Graphics, this._icon.ToBitmap(),
e.Bounds.Left + ((e.Bounds.Width - this._icon.Width) / 2),
e.Bounds.Top+ICON_PAD_TOP, br.Color);
}
}
Benny Raymond wrote:
I've written a class that inherits from MenuItem which displays icons
next to the items in a menu... The only problem I'm having is that I
have no clue how to turn these icons greyscale if they're item is
disabled. Right now I'm turning the text grey and would like to also
grey out the icon. Any help would be awesome. here's my code for
drawing the icon:
if ( this._icon != null )
{
if ( this.Text != "" && this.Text != "X" )
e.Graphics.DrawIcon(this._icon, e.Bounds.Left+ICON_PAD_LEFT,
e.Bounds.Top+ICON_PAD_TOP);
else
e.Graphics.DrawIcon(this._icon, e.Bounds.Left + ((e.Bounds.Width
- this._icon.Width) / 2), e.Bounds.Top+ICON_PAD_TOP); // center the icon
}