473,779 Members | 1,884 Online
Bytes | Software Development & Data Engineering Community
+ 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.Form 1' 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 3026
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.Form 1' 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.NotImple mented 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 ()
InitializeCompo nent()
End Sub

Public Overridable Sub MakeMeDoCoolStu ff ()
Throw New System.NotImple mentedException ("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.Form 1' 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.NotImple mented 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 MakeMeDoCoolStu ff ()
Throw New System.NotImple mentedException ("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
1297
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 inherits from FormA. FormB for some odd <and stupid> reason, FormB desides to rewrite all the designer generated code for the inherited controls. It also puts the images that FormA has in it's resx into it's own resx <very annoying>. I have MANY forms...
1
1289
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 this base form...The problem I notice so far is that if the controls in the base form don't have the "friend" modifier , the form designer will regenerate the intial code for each control in the inherited form.....This is causing me headache...If i...
0
1910
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 several user controls that are inherited user controls, based on one class, which is in turn based on System.Windows.Forms.UserControl. We'll call this class "UserControlBase". My first problem is that UserControlBase implements some public...
4
3159
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 further away, completely leaving the selector box area. Any ideas? VS 2003 and VB.Net This is a simple application at the moment but the form is inherited from a
2
3220
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 side of the form. It would be really nice if I could design all possible right hand side panels in the forms designer, then have some way to tell the framework "load the form represented by the class SuchAndSuchForm". What I have to resort to...
6
1879
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 exception. My question is: "how can I debug visual studio form designer?" As I remember in Visual 6.0 it was possible by running two visual session and attaching first one to the second. Unfortunately in VS .NET 2005 it seems that it doesn't work. What...
4
5833
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 the resizing tool (in the designer) is offset both horizontally and vertically and when I put a control on it, as soon as I save, the designer throws an exception (but cannot be reproduced everytime) and the form cannot be loaded anymore unless...
0
1181
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 classes) so that future changes in these controls are managed by just modifying this custom layer, and not all the controls of a particular type.
8
2317
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 number of elements) to be determined at runtime, so dragging and dropping on the Form Designer won't cut the mustard. I'm coming from a Java background, and have almost always built my GUI's programmatically, but I realize that in C# this practice...
0
9632
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10302
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10071
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9925
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8958
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7478
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5501
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4036
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2867
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.