putting custom control on a form that inherits from my form class, doesn't work

C

Capital O

VS2005 RTM, CF 2.0, PocketPC 2003 SE

I created a base form class called MyBaseForm that inherits from Form.
I implement significant presentation helper functionality in this base
class. I can add an inherited form to my project (Form1), inherit from
MyBaseForm, and I get the designer, and all at first appears good. But
when I try to site my custom control (which inherits from TextBox) on
Form1, I get the following error:

Code generation for property 'HintStatusBar' failed. Error was:
'Object reference not set to an instance of an object.'

When I add my custom control to a regular form (inheriting directly
from System.Windows.Forms.Form), I don't have this problem, and my
control works fine.

I created a second, separate project, using a highly simplified base
form class, and reproduced the problem immediately. (I hoped for a
solution/project file corruption to explain it, but it wasn't in the
stars.)

HintStatusBar is a Control type which should be null, and the designer
shouldn't be trying to generate any code for this within
InitializeComponent. When I comment out HintStatusBar, I get the same
error message with other properties of type Control.

I've been reading the newsgroups and googling for this error message,
and have found it everywhere, but nowhere like what was happening to
me. I saw a recommendation to use a DesignerSerializationVisible
attribute to deflect the code generator away from it, but when I do a
search in VS2005's help I get basically nothing, and within
System.ComponentModel, I don't even see that attribute. Was this a
beta 2 feature that disappeared at RTM time?

To my further frustration, all of this was working with no problems
when I first set up the project, and only on day two, when I'm adding
another inherited form, has the problem arisen.

If I have to, I can inherit from Form, and when ready to compile,
change them all to MyBaseForm. But I've been waiting very patiently
for CF 2.0 and all the promises that this type of form inheritance
would work and work smoothly, and if there's a trick to avoiding such a
kludgey development process, I'd be indebted.

Any ideas?
 
C

Capital O

Thanks, Alex! After reading Xin Yan's article on creating custom
controls, I was able to set the attributes in the class designer and
get my controls to work.

Xin Yan suggested that the class designer is an easier way to add
attributes such as DesignerSerializationVisibility. However, it
appears that this is the ONLY way to add these attributes to a CF
project, since those attributes don't appear in Intellisense and aren't
supported in CF. It looks like adding them through the class designer
is a way to get around that and to use full .NET Framework attributes
that wouldn't otherwise be available. (And also CategoryAttribute,
DescriptionAttribute, etc.)

This should be documented explicitly methinks. So a few questions
remain. Why does Microsoft want us to write ShouldSerializeXXX methods
instead of just checking to see if a reference type is null and only
serializing if it isn't? (Are there scenarios where this is needed?
And will it always cause errors while saving and generating code? It
seems CF v1.0 at least had this much sense.) And why are simple
attributes like Category and Description not present in the CF subset?

Things that make you go hmmm....
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top