M
mrabie
Hi all,
I am writing a class that inherets from the Button control to draw a
custom image on it. I override the OnPaint event but it never gets
called and the button draws the default shape n color... any ideas why
it might be doing that?
Thank
here's the code:
public partial class OSImageButton : Button
{
Bitmap _Image = null;
Bitmap offScreen;
Graphics gxBuffer;
public OSImageButton()
{
InitializeComponent();
offScreen = new Bitmap(this.Width, this.Height);
gxBuffer = Graphics.FromImage(offScreen);
}
public OSImageButton(IContainer container)
{
container.Add(this);
InitializeComponent();
offScreen = new Bitmap(this.Width, this.Height);
gxBuffer = Graphics.FromImage(offScreen);
}
public Bitmap Image
{
get { return _Image; }
set { _Image = value; }
}
protected override void OnPaint(PaintEventArgs e)
{
if (_Image != null)
{
gxBuffer.DrawImage(_Image, 0, 0);
e.Graphics.DrawImage(offScreen, 0, 0);
}
else
{
base.OnPaint(e);
}
}
}
I am writing a class that inherets from the Button control to draw a
custom image on it. I override the OnPaint event but it never gets
called and the button draws the default shape n color... any ideas why
it might be doing that?
Thank
here's the code:
public partial class OSImageButton : Button
{
Bitmap _Image = null;
Bitmap offScreen;
Graphics gxBuffer;
public OSImageButton()
{
InitializeComponent();
offScreen = new Bitmap(this.Width, this.Height);
gxBuffer = Graphics.FromImage(offScreen);
}
public OSImageButton(IContainer container)
{
container.Add(this);
InitializeComponent();
offScreen = new Bitmap(this.Width, this.Height);
gxBuffer = Graphics.FromImage(offScreen);
}
public Bitmap Image
{
get { return _Image; }
set { _Image = value; }
}
protected override void OnPaint(PaintEventArgs e)
{
if (_Image != null)
{
gxBuffer.DrawImage(_Image, 0, 0);
e.Graphics.DrawImage(offScreen, 0, 0);
}
else
{
base.OnPaint(e);
}
}
}