|
-
January 16th, 2010, 05:46 AM
#1
Designer doesn't create instances of custom controls
Hello all,
I've just experienced a very odd problem, so I'm posting here hoping to get some help.
I'm using Visual Studio 2008 and C#. I've added a custom control to my project that extends the standard Button class. I've only changed a few properties of this control (like back and fore color). Now when I drag&drop this control from the toolbox onto a form, everything looks ok. The control is displayed as it should be, Designer gives no errors.
However, when I try to run my project, I get the Object reference not set to an instance of an object exception. I've done some research and found out the exception was caused by my control, since it never got instantiated. Looking at Designer-generated code, there is no sentence stating:
button1 = new MyButton();
There is a button1 field though. And of course, I didn't modify any of Designer-generated code.
I can add the missing line manually and then the code works, but only until I change something in the form. The the Designer code gets regenerated and the line is lost again.
Can someone please tell me what on earth is going on? I've created quite some custom controls so far and never seen anything like this. Am I doing something wrong or is this just Visual Studio playing games with me?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|