C# Control not creating a new instance...

  • Thread starter Thread starter Ralph Wiggum
  • Start date Start date
R

Ralph Wiggum

I have created a control in C# and it works a treat, however, when I
drop the control into a C# Windows Forms application, it does a very
odd thing. It creates the control in design mode, but when I run the
application, the control is nowhere to be seen.

Looking at the form designer generated code in the InitializeComponent
function, it has not added the code to create a instance of my
control.

ie. this.MyControl= new MyControl();

it has however, created the code in InitializeComponent() to add it to
the form...

Other controls I have created work fine, it's just this one, so I
think there is something wrong with my control, but having been
tearing my hair out all morning, and trying everything I know (which
is not alot..), I am still no further down the road to solving
this....

PS. If I add the code to create a new instance, then it works, until I
change somehting on the form, it then disappears.

Anyone got any ideas?
 
I'm surprised that you see it in design mode but not at runtime. If you see
it at design time, it must be adding it to the controls collection. You can
paste in the 'windows form designer' generated code, and point out which
control is the one you're having difficulty with?
 
John Wood said:
I'm surprised that you see it in design mode but not at runtime. If you see
it at design time, it must be adding it to the controls collection. You can
paste in the 'windows form designer' generated code, and point out which
control is the one you're having difficulty with?

I found out what the probelm was, it was a type converter that I wa
using in my controls class. I moved this into the class, around the
function that uses the typeconverter (rather than the whole class),
and it started working again correctly.

Still don't understand why....
 
Back
Top