Do inherit from your controls
It is very easy to inherit from your controls in dotnet/VS.Net. Just add a class and let it inherit from any Control. That’s it!
To use it either reload the project (possibly the IDE) and drag it from the toolbox to the left. This is only possible in VSNet2005 I think. Or do as I, open the myclass.designer.cs file and edit the declaration in the bottom. Recompile and edit the compiling error at the instantiation. That’s it!
VSNet2005 does not interfere with your hacking of the .designer.cs file. Unless you are building for WinCE that is.
Why inherit then?
There is really no need to do it all the time.
But keep it in your head so the moment you need some common functionality in your form you can put it in BaseForm.
Update:
Always inherit from the grid control. There is a very good reason regarding type safety and differentiation of data and view for this. I hope to write about this in a not to far future.
Update:
Hacking designer.cs in VSNet2008 for WindowsMobile(6.1) works alright but you will probably get an “InvalidCastException” and a pointer to something like
((System.ComponentModel.ISupportInitialize)(this._myControl)).BeginInit();
The error is explained here and the solution is to just comment/delete the rows
((System.ComponentModel.ISupportInitialize)(this._myControl)).BeginInit();
and
((System.ComponentModel.ISupportInitialize)(this._myControl)).EndInit();
Tags: solid code