views:

786

answers:

4

I've created a custom control (a class that inherits from Control). When I put it on a Form I can work with it on Visual Studio IDE. It shows me an error and I don't see the form.

The error message is this: La variable 'ctrlImagen' no está declarada o no se asignó nunca.

It's a winform for a Compact Framework app.

How can I solve this? (it the class inherits from UserControl it works perfectly)

+1  A: 

It sounds like you have a bug in the code for your Control. This sounds like a runtime error that is preventing the control from rendering.

Re-read your code and look for potential null-pointer exceptions, unassigned variables, stack overflows, etc. The bug is lying in their somewhere.

Frank Krueger
+2  A: 

Sounds crazy, but Visual Studio is selectively executing code for your control in the designer. First thing to check is your constructors. Make sure you have an empty, default constructor, that is public, even if you never plan on using it. After that make sure any code you have tied to layout events (such as resize) are good to go, these are likely the culprits, as thats where I always find problems when my custom controls don't work in the designer.

Neil N
+1  A: 

Any chance your user control doesn't have a public default constructor? I can get a similar error "The variable 'userControlX' is either undeclared or was never assigned' if the constructor isn't public.

Would need more info, though.

itsmatt
If class inherits from UserControl it works perfectly.
VansFannel
A: 

I put this on constructor to solve the problem: this.ClientSize = new Size(21, 21);

The beging of my class is this:

    public class ControlMapa : Control
    {
        public ControlMapa()
        {
            this.ClientSize = new Size(21, 21);
            ...

Thank you!

VansFannel