views:

91

answers:

1

Okay... I'm writing a .NET CF (VBNET 2008 3.5 SP1) application, which has one master form, and it dynamically loads specific UserControls based on menu click, in a sort of framework idea.

There are certain methods and properties these controls all need to work within the app.
Right now I am doing this as an Interface, but this is aggravating as all get up, because some of the methods are optional, and yet I MUST implement them by the nature of interfaces.

I would prefer to use inheritance, so that I can have certain code be inherited with overridability, but if I write a class which inherits System.Windows.Forms.UserControl and then inherit my control from that, it squiggles, and tells me that UserControls MUST inherit directly from System.Windows.Forms.UserControl. (Talk about a design flaw!)

So next I thought, well, let me use a partial class to extend System.Windows.Forms.UserControl, but when I do that, even though it all seems to compile fine, none of my new properties/methods show up on my controls.

Is there any way I can use partial classes to 'extend' System.Windows.Forms.UserControl? For example, can anyone give me a code sample of a partial class which simply adds a MyCount As Integer readonly property to the System.Windows.Forms.UserControl class? If I can just see how to get this going, I can take it from there and add the rest of my functionality.

Thanks in advance! I've been searching google, but can't find anything that seems to work for UserControl extension on .NET CF. And the Interface method is driving me crazy as even a small change means updating ALL the controls whether they need to 'override' the method or not.

EDIT: I'm looking really for a way to do simply code inheritance if possible, without visual inheritance. My controls share no common visual elements, I really only need to inherit common functionality in the code-behind.

+1  A: 

I just tested UserControl inheritance in a SmartDevice project, it works fine.
I used a BaseUserControl created from the UC template, not just a class.

Henk Holterman
Well, I'm going more for a "code-behind" inheritance, ... common functionality, not so much a visual inheritance, as the various controls comprising the modules do not have any shared visual similarities really. But for example, they all must have Init, Save, Clear methods, a Count property, **some** override a Done method, etc. Nothing to do with the UI of the control at all. I suppose if I need to I may be able to go this way, but it seems AWFULLY kludgey.
eidylon
@eidylon: Just don't add any controls... It's just to satisfy the designer (probably wants a .resx and .Designer.cs in the right place and form).
Henk Holterman
I'm awarding the points because I think basically this does the same thing as how I finally got it to work. I did "show all project files", and then edited the Inherits line in MyControl.Designer.vb file, and then it worked fine. Id be curious Henk, if you view the designer.cs file for your inherited control, has it actually changed the inherited baseclass in there to your base class?
eidylon
I'm not sure about vb but in C# only 1 part of a partial class can specify the base class. And that is in the non-designer file.
Henk Holterman
See, that was where I originally tried specifying the baseclass was in the non-designer file... the ctl.vb (as opposed to ctl.designer.vb), and that was when it yelled at me about "*must* inherit System.Windows.Forms.UserControl'. Guess that must be a diff between the C# and VB compilers. Ah well... thanks for the help Henk; cheers!
eidylon
Yes, I just took a look: VB only allows 1 place too but (the template) chooses to use the Designer.vb
Henk Holterman