Manually Add a Resource File (Visual Studio)
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 ic开发者_JS百科o) 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?
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 doesn't mean you cant set up a designer for it.
精彩评论