views:

364

answers:

2

It seems like a simple task. Create a C# class that derives from ToolStripButton. The derived ToolStripButton should behave exactly the same as the parent class in the designer and the application, except that the default image should be different.

Surprisingly just changing the constructor is not sufficient:

public CustomToolStripButton()
{
    base.Image = (Image) new Bitmap(typeof(CustomToolStripButton), "CustomImage.bmp");
}

When the ToolStripButton is displayed in the designer, the original default image is shown. There must be a simple solution. What could it be?

A: 

i used the same code for this... i am able to see the new image ..

please comment the adding image to toolStripButton intialization in InitializeComponent of form

this is the code... //this.toolStripButton1.Image = ((System.Drawing.Image)(resources.GetObject("toolStripButton1.Image")));

Kasma
The problem with this is you need to manually edit the form's designer every time you make a change to the form. I'm looking for the derived ToolStripButton to behave the same as its parent without manually editing auto-generated code.
Special Touch
A: 

I'm trying to do the same and have overridden the property Image like this:

[Browsable(true), DefaultValue(typeof(Image), "")]
public override Image Image
{
     get{return base.Image;} 
     set{base.Image = value}
}

This doesn't work, the ToolStripButton that i derive from still generates code in InitializeComponent and ads the line:

this.mdiTab1.Image = ((System.Drawing.Image)(resources.GetObject("mdiTab1.Image")));

So how is one to override the default value? and make it work in the designer? either with a default image or (none).

or do i have to use some event on the ToolStrip when i add a ToolStripButton and from there replace the Image?

Mustin