Sibling classes

  • Thread starter Thread starter Michael Maes
  • Start date Start date
M

Michael Maes

Hi,

I have a "Sibling Classes" issue:

° I have some Classes (forms) all Subclassed from System.Windows.Forms.Form.

° I have Classes in which there is a Property "OwnerForm" (for Components).

That poperty must accept:

° System.Windows.Forms.Form
° Subclassed Form_A
° Subclassed Form_B
° Subclassed Form_B_X
° Subclassed Form_B_Z
° Subclassed Form_C

For the property to accept all those Sibling-Classes, I could put it's type to Object.
Checking the Type in the Set of the Property is no problem

BUT:

The property can also be set in Design-Time, so it's Available to the "Property-Browser" (<EditorBrowsable(EditorBrowsableState.Always), Browsable(True), ....)

And the last thing I want is a messy feeling being able to select "All kind of Objects".

THEREFORE:

Is there a way to Set the Type of a Property to ALL SubClasses of a Certain BaseType?

(I don't think so, but you never know....)

If not: is there a way to tell vs to show Only BaseType & DerivedTypes of a certain Object in the DropDownPortion of a Combo in the Property-Window.

This all is in vb.Net 2003

TIA,


Michael
 
Hi Michael,

I wonder why you did not set the type of the property to Form directly,
because it seems that all the "Sibling Classes" you are using inherits from
Form.
Also can you post some code snippet to show us what you want to do?
I will appreciate your efforts.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Hi Peter,

The Forms:

Namespace MyNamespace.Windows.Forms
Public Class FormA
Inherits System.Windows.Forms.Form
........

Namespace MyNamespace.Windows.Forms
Public Class FormB
Inherits System.Windows.Forms.Form
........

Namespace MyNamespace.Windows.Forms
Public Class FormC
Inherits System.Windows.Forms.Form
........

Namespace MyNamespace.Windows.Forms
Public Class FormB_A
Inherits MyNamespace.Windows.Forms.FormB
........

Namespace MyNamespace.Windows.Forms
Public Class FormB_B
Inherits MyNamespace.Windows.Forms.FormB
........

The Components (eg Typed DataSets):

Public Class tdsA
Inherits schemaA (Generated Schema by Visual Studio)
........
' OwnerForm
Dim _OwnerForm As MyNamespace.Windows.Forms.FormB
<EditorBrowsable(EditorBrowsableState.Always), _
Browsable(True), _
Category("Blabla"), _
Description("The container-form of the current DataSet-Instance.")> _
Public Property OwnerForm() As MyNamespace.Windows.Forms.FormB
Get
Return _OwnerForm
End Get
Set(ByVal Value As MyNamespace.Windows.Forms.FormB)
' Perform some checkings
............
_OwnerForm = Value
End Set
End Property


So in OwnerForm I want to be Able to stuff all current Forms (types), but more important: also future Forms (new derived types)
So basically: every form which is eventually derived from System.Windows.Forms.Form.

Regards,


Michael
 
Wow Peter,

I just tried this ("one never knows") and it works:

Public Property OwnerForm() As Form

How is this possible?
Will this property accept all form-derived types?

I just assumed that defining the type as System.Windows.Forms.Form would't
allow Subclasses of that class.

Thanks,

Michael
 
Hi Michael,

In .NET framework all type inherits from Object, so every type is kind of
object.
Analogously, since all the sub class you are using inherits from Form, so
they are a kind of Form(BaseClass).
e.g.
Object---->Shape---->Rectange---->square
The square should be a kind of Shape.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Thanks for this (obvious) clarification.
I have been Coding vb for nearly three years now, and have always
thought/assumed that the type "narrowed down" along with it's subclasses. I
you think how many times I've used "Object" as a placeholder.... it's
correct to tell I've been "blind" (and stupid) all those years.

Thanks alot Peter,

Michael
 
Back
Top