473,473 Members | 2,161 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Designer can't display inherited form

VS 2008
I have a windows form that was created in the normal way using the form
designer. I do not wish to use this form directly though, I want to use it
as a basis for some other forms. I have added a MustOverride Sub and have
added MustInherit to the class definition. I then created a second form,
this time by adding a class module, and specifying that it inherits from my
first form.
It all works fine, but when I double-click on the second form in Solution
Explorer it tries to open it using the Form designer which displays an error
message: "The designer must create an instance of type 'MyProject.Form1' but
it cannot because the type is declared as abstract.".
Is there any way to either fix this error, so that it displays correctly in
the designer, or to stop the IDE from trying to use the designer and take me
straight into the code view? The first form (the abstract one) displays in
the designer with no problems.
TIA
Phil.
Sep 9 '08 #1
4 3009
On 2008-09-09, Phil <N/Awrote:
VS 2008
I have a windows form that was created in the normal way using the form
designer. I do not wish to use this form directly though, I want to use it
as a basis for some other forms. I have added a MustOverride Sub and have
added MustInherit to the class definition. I then created a second form,
this time by adding a class module, and specifying that it inherits from my
first form.
It all works fine, but when I double-click on the second form in Solution
Explorer it tries to open it using the Form designer which displays an error
message: "The designer must create an instance of type 'MyProject.Form1' but
it cannot because the type is declared as abstract.".
Is there any way to either fix this error, so that it displays correctly in
the designer, or to stop the IDE from trying to use the designer and take me
straight into the code view? The first form (the abstract one) displays in
the designer with no problems.
TIA
Phil.
The error makes some sense, as the designer is trying to create an instance
of a MustInherit class (abstract class) - which is not possible. The way I
usually overcome this, is to remove the MustInherit and change the
MustOverride to Overridable (virtual) in the base class - then I will usually
throw a System.NotImplemented exception (you can create a custom exception
here if you want, but I don't usually bother) from the base class versions of the
methods. This will allow the designer to create the instance of the form, and
still force derived classes to implement the base class methods - unless they
want the exception :) To be clear, here is what a base form might look like:

Public Class BaseForm
Inherits System.Windows.Forms.Form

Public Sub New ()
InitializeComponent()
End Sub

Public Overridable Sub MakeMeDoCoolStuff ()
Throw New System.NotImplementedException("You didn't override me!)
End Sub
End Class

--
Tom Shelton
Sep 9 '08 #2
On Tue, 9 Sep 2008 16:28:44 +0100, "Phil" <N/Awrote:
>VS 2008
I have a windows form that was created in the normal way using the form
designer. I do not wish to use this form directly though, I want to use it
as a basis for some other forms. I have added a MustOverride Sub and have
added MustInherit to the class definition. I then created a second form,
this time by adding a class module, and specifying that it inherits from my
first form.
It all works fine, but when I double-click on the second form in Solution
Explorer it tries to open it using the Form designer which displays an error
message: "The designer must create an instance of type 'MyProject.Form1' but
it cannot because the type is declared as abstract.".
Is there any way to either fix this error, so that it displays correctly in
the designer, or to stop the IDE from trying to use the designer and take me
straight into the code view? The first form (the abstract one) displays in
the designer with no problems.
TIA
Phil.
Instead of double-clicking, right-click and select View Code.
Sep 9 '08 #3
The error makes some sense, as the designer is trying to create an
instance
of a MustInherit class (abstract class) - which is not possible. The way
I
usually overcome this, is to remove the MustInherit and change the
MustOverride to Overridable (virtual) in the base class - then I will
usually
throw a System.NotImplemented exception (you can create a custom exception
here if you want, but I don't usually bother) from the base class versions
of the
methods. This will allow the designer to create the instance of the form,
and
still force derived classes to implement the base class methods - unless
they
want the exception :)
Thanks. I had thought of just including a blank method and marking it
overridable, but I hadn't thought of raising an exception, that sounds like
the best option if there is no attribute I can add to tell the IDE not to
use the designer.

Another solution I have found is to add another class definition in the same
source code file. I have some other classes that inherit from control
classes. If I put one of these in the same source file, before the source
for the form, the designer will not try to work with the form and will
display a handy link to switch to code view.

Cheers,
Phil.
Sep 10 '08 #4
Hi,

Tom Shelton wrote:
Public Overridable Sub MakeMeDoCoolStuff ()
Throw New System.NotImplementedException("You didn't override me!)
End Sub
that sure is a neat approach to the problem that I didn't think of when I
had the exact same problem a year ago (damn!). As a result, I gave all
methods and properties that needed to be overrided a common prefix (and I
still hate it).

Back then I also posted a question in the NGs about this. The answer I got
was to build a separate DLL with the base form and reference that in the
project where I'm creating inherited forms. In my case though the base form
itself needed access to some of the application's data layer classes, hence
I didn't try it out - it would've caused too much work to completely change
the application and I never found the time to actually give it a shot in
some test-project.

Robert, maybe you want to try that out ..? I'd sure be interested in the
results.

Cheers,
Olaf
Sep 11 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Patrick Corkum | last post by:
Hello, I am having a really annoying problem. I have a base form, say FormA, and this form has some buttons on it with images (which are stored in the resx file). I then have FormB, which...
1
by: Dayne | last post by:
I have a problem with how visual studio.net's form designer handles form inheritance. This is what I am trying to do.. I have a base form with some controls on it..I then create a child Form from...
0
by: Jim | last post by:
I am having some trouble with user controls and would appreciate any input / advice on where to go with this... :) 1. The first problem, and perhaps the root of the others, is that I have...
4
by: Rod Gill | last post by:
Hi, I have a form that when opened in the designer appears of the screen. The form selector can't be dragged (or resized) and if I scroll right and down to centralise it the form simply jumps...
2
by: Zach | last post by:
I have a situation similar to what you see in Visual Studio Options menu. A Tree View on the left, and depending on what type of node you click it dynamically loads a panel into the right hand...
6
by: Arkadiusz Smolak | last post by:
Hi, I need a help. I have form inherited from other form. The base form implementation is placed in other assembly. I try to open my inherited form in designer but visual studio throws an...
4
by: ThunderMusic | last post by:
Hi, I have a custom form that works fine when I debug it or run it in release mode but cannot be loaded in the designer... Actually, it can be loaded in the designer when no control is on it, but...
0
by: =?Utf-8?B?SGVsZ2U=?= | last post by:
Hi! I have run into a problem with visual inheritance using the VS2005 designer for Windows Forms. My goal is to put business logic and common rules for our controls into its own layer (base...
8
by: TomC | last post by:
I want to bypass the Windows Form Designer in VS, to create a form programmatically. The elements of the form are to be arranged in a table, and I want the size of the table (and therefore the...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.