Abstract Form Class

G

Guest

H
I wonder can anyone answer - can I create a form which is an abstract class i.e. has the MustInherits keyword in the class definitio

When I do this I get the error message

'New' cannot be used on a class that is declared 'MustInherit'

This happens before I have put any other code on the system, all I have done is entered the MustInherits keyword - this is all the code in the form

Public MustInherit Class Form
Inherits System.Windows.Forms.For

#Region " Windows Form Designer generated code

Public Sub New(
MyBase.New(

'This call is required by the Windows Form Designer
InitializeComponent(

'Add any initialization after the InitializeComponent() cal

End Su

'Form overrides dispose to clean up the component list
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean
If disposing The
If Not (components Is Nothing) The
components.Dispose(
End I
End I
MyBase.Dispose(disposing
End Su

'Required by the Windows Form Designe
Private components As System.ComponentModel.IContaine

'NOTE: The following procedure is required by the Windows Form Designe
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent(
components = New System.ComponentModel.Containe
Me.Text = "Form1
End Su

#End Regio

End Clas

I have another form which has more properties and methods etc and I get a similary message
'New' cannot be used on class 'FormTemplates.frmStandardDataEntry' because it contains a 'MustOverride' member that has not been overridden

Any help is greatly appreciated
Thank
Siobha
 
H

Herfried K. Wagner [MVP]

* "=?Utf-8?B?U2lvYmhhbg==?= said:
Hi
I wonder can anyone answer - can I create a form which is an abstract class i.e. has the MustInherits keyword in the class definition

When I do this I get the error message:

'New' cannot be used on a class that is declared 'MustInherit'.

That's a limitation of the Windows Forms designer.
 
S

Stoitcho Goutsev \(100\) [C# MVP]

Hi Sioban,

When the designer opens a form for designing it creates an object of its
base class. So when you create a form that inherits from that *abstract*
form the designer is trying to instantiate the *abstract* class and it
fails.

So, don't declare form classes as *abstract* if you want to use the
designer.
--
HTH
B\rgds
100 [C# MVP]


Siobhan said:
Hi
I wonder can anyone answer - can I create a form which is an abstract
class i.e. has the MustInherits keyword in the class definition
When I do this I get the error message:

'New' cannot be used on a class that is declared 'MustInherit'.

This happens before I have put any other code on the system, all I have
done is entered the MustInherits keyword - this is all the code in the form:
Public MustInherit Class Form1
Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

Public Sub New()
MyBase.New()

'This call is required by the Windows Form Designer.
InitializeComponent()

'Add any initialization after the InitializeComponent() call

End Sub

'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer

'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
components = New System.ComponentModel.Container
Me.Text = "Form1"
End Sub

#End Region

End Class

I have another form which has more properties and methods etc and I get a similary message:
'New' cannot be used on class 'FormTemplates.frmStandardDataEntry' because
it contains a 'MustOverride' member that has not been overridden.
 
G

Guest

Thanks for your responses

Is there any way then that I can create a form template, but which has some functions that canbe cusomised depending on the forms use. What I am trying to do is create a standard data form which would have overridable methods where I could have created the specific insert, delete, update, select functions depending on the form. What I have done in the meantime is create a non-abstract form with these functions as overridable, but I would have liked to enforce the overridable. Is there another way to do that
Thanks agai
Siobhan
 
S

Stoitcho Goutsev \(100\) [C# MVP]

Hi Siobhan,

I can't think of any way to force overriding except if you thorw an
axception in the default implentation (say NotImplementedException). But you
cannot force inhertors to override the member.

--
B\rgds
100 [C# MVP]

Siobhan said:
Thanks for your responses!

Is there any way then that I can create a form template, but which has
some functions that canbe cusomised depending on the forms use. What I am
trying to do is create a standard data form which would have overridable
methods where I could have created the specific insert, delete, update,
select functions depending on the form. What I have done in the meantime is
create a non-abstract form with these functions as overridable, but I would
have liked to enforce the overridable. Is there another way to do that?
 
A

Andrew Bingham

Unless i misunderstood your question....

Visual inheritance is one of the key benefits of VB.NET.

A form can inherit from another form, and you can call the base form methods
and events (nybase.method) or override them in the subclassed forms, (or do
both of courses)

I have built an application that does exactly this.



--
****************************************************************************
andrewbingham.com

tel 01223 514674 (Cambridge)
mobile 07970 161057
fax 07970 601283
email (e-mail address removed)

DISCLAIMER, PLEASE NOTE:
This communication is for the attention of the named recipient only
The content should not be passed on to any other person.
It is sent in good faith, in confidence, and without legal responsibility.

VIRUS CHECK
Emails and attachments are virus checked using Norton® AntiVirus®
2002 which is regularly updated. However it remains the recipients
responsibility to check emails and attachments sent, or forwarded,
from andrewbingham.com for viruses and macro viruses
****************************************************************************
Siobhan said:
Hi
I wonder can anyone answer - can I create a form which is an abstract
class i.e. has the MustInherits keyword in the class definition
.
When I do this I get the error message:

'New' cannot be used on a class that is declared 'MustInherit'.

This happens before I have put any other code on the system, all I have
done is entered the MustInherits keyword - this is all the code in the form:
Public MustInherit Class Form1
Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

Public Sub New()
MyBase.New()

'This call is required by the Windows Form Designer.
InitializeComponent()

'Add any initialization after the InitializeComponent() call

End Sub

'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer

'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
components = New System.ComponentModel.Container
Me.Text = "Form1"
End Sub

#End Region

End Class

I have another form which has more properties and methods etc and I get a similary message:
'New' cannot be used on class 'FormTemplates.frmStandardDataEntry' because
it contains a 'MustOverride' member that has not been overridden.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top