views:

213

answers:

1

I have a solution in VB.NET (VS 2005)

In this solution I have a custom control, that inherits from a abstract class.

Now, as VS is VS, it doesn't want to display the control in designer, because its parent is abstract.

Now, I want to add a picturebox with an image (bmp or ico) to this control. Normally I've done this opening the designer and dragging a picturebox, selection also a image in background.

But as designer is unavailable, how can I do adding however the image to my control?

+1  A: 

You have two options:

1. Add the image as a project resource, then and create and add the PictureBox control at runtime.

This is a little messy, but solves the problem. Add the image to the project resources. And at runtime do something like this:

PictureBox pb = new PictureBox();
pb.Image = (Bitmap)global::MyProject.MyImage;

myCustomControl.Controls.Add(pb);
pb.Location = new Point(x,y);  
// and any other properties that need setting

2. Fix the design time properties of your control

This is the better long term solution. MSDN has a lot of info about "Designer" attributes, which is sort of like code that runs in design mode, so that you can interact with a control in Visual Studio. Sometimes VS is pretty good at figuring out some parts for the designer for you, other times you have to give it some help. Just because a control is based on an abstract class doesnt mean you cant set up a designer for it.

Neil N
so, the second part is interesting. So, what attribute can "tell" VS to "ignore" the abstract parent?
serhio
You're not "ignoring" the parent as much as you would be "Adding" a designer to the inherited control.
Neil N