Designer Erases my components

  • Thread starter Thread starter zc2468
  • Start date Start date
Z

zc2468

Using vb.net I created a new class based on a textbox. I wanted to
apply this new class to a number of textboxes that I carefully laid out
on a form using the vs designer. So, I changed 2 lines of code for
each original textbox control to switch from the textbox control to my
textboxplus control. The first time I ran the program everything
worked as intended, but then the designer erased my components.

I can understand why this happened because I modified the designer
generated code. My question is, how do I enable my component to be
recognized by the designer so that I can add it to the toolbox and us
it just like any other control?

I've done some searching about this, but I can't find any information
regarding doing this using the COMPACT framework with vb.net.
Thanks in advance...

D
 
You can only create custom controls with designer support in C# (for NETCF
1.0) not VB. If you wish to pursue that route check out this articles:
http://www.intelliprog.com/articles/index.html
http://msdn.microsoft.com/library/d...ngcustomcontrolforsmartdeviceapplications.asp

Otherwise, as you have found out you will lose changes whenever you make
changes to the designer. To prevent accidentally opening a form in designer
view you can apply an attribute to the form e.g.:
<System.ComponentModel.DesignerCategory()> _
Public Class Form1

Cheers
Daniel
 
Thank you for the quick reply. Though I want to learn C#, I'm not
ready to do it just yet to complete this small project.

The idea of disabling the designer entirely seems kind of
counterproductive to me, so I thought I would redo my layout with the
designer, then move the generated code elsewhere to create my controls
on the fly. That way I can at least take advantage of the designer for
other elements and for layout.

Anybody else try doing this? If so, any other advice or ideas for a
vb.net person? Hopefully this thread will be beneficial to others!
Thanks,

D
 
Yes, the approach you describe is fine.

After the call to InitializeComponent, in the ctor, place your additional
statements for creating, laying out and parenting the custom controls while
the rest of your form is designable in the IDE.

Cheers
Daniel
 
Back
Top