473,586 Members | 2,681 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Inheritable Forms: Abstract

I am trying to create a base form that all of our application's forms will
inherit from. I would like to mark it "abstract", but if I do, I get an
error from the form designer when I try to design forms that are
(non-abstract) children of the base form. The designer complains about not
being able to instance the base class (though I am designing the child
class). Now, I know that I could just use virtual methods and properties
instead of abstracts, and I could give my base form a private constructor to
keep people from instancing it directly.

However, I could have sworn that I came across some way of making the form
designer work with an abstract form. I thought that it had something to do
with placing an attribute in the child class, but I just can't seem to
remember what the attribute was (or if it's even real). Any hints?

-- Jeremy
Nov 15 '05 #1
1 4831
Jeremy,
The forms designer needs to create an instance of the base class, as you are
able to set properties of the base class when you design the child class.

The general workaround is to have your base form abstract for release builds
of your app, but concrete for debug builds. This enables you to design the
form, during debug builds, then change to release builds and compile that
way.

What I do in the debug stub methods, is throw a NotImplementedE xception, as
a reminder that my derived classes need to implement the method.

Something like (untested):

#if DEBUG
public class FormBase : Form
{
#else
public abstract FormBase : Form
{
#endif

#if DEBUG
public virtual void MyMethod()
{ throw new NotImplementedE xception(); {
#else
public abstract void MyMethod();
#endif

Hope this helps
Jay

"J.Marsch" <je****@ctcdeve loper.com> wrote in message
news:%2******** ********@TK2MSF TNGP10.phx.gbl. ..
I am trying to create a base form that all of our application's forms will
inherit from. I would like to mark it "abstract", but if I do, I get an
error from the form designer when I try to design forms that are
(non-abstract) children of the base form. The designer complains about not being able to instance the base class (though I am designing the child
class). Now, I know that I could just use virtual methods and properties
instead of abstracts, and I could give my base form a private constructor to keep people from instancing it directly.

However, I could have sworn that I came across some way of making the form
designer work with an abstract form. I thought that it had something to do with placing an attribute in the child class, but I just can't seem to
remember what the attribute was (or if it's even real). Any hints?

-- Jeremy

Nov 15 '05 #2

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

Similar topics

2
2285
by: Mark | last post by:
Hi all, quick question, how do I make a define a class as being inheritable only?? Thanks Mark
1
3743
by: KK | last post by:
Windows Forms Inheritance, Incomplete? I was playing around with Windows Forms and found out this Forms Inheritance feature. The moment I saw that, I felt this can be used effectively if the application contains couople of forms which have a consistant look and also shares SOME similar functionality between the forms.
2
2191
by: KK | last post by:
** Posting it here cause after couple of days no body responded.** I was playing around with Windows Forms and found out this Forms Inheritance feature. The moment I saw that, I felt this can be used effectively if the application contains couople of forms which have a consistant look and also shares SOME similar functionality between...
1
2850
by: Dave Veeneman | last post by:
I'm creating several forms that inherit from a base form. I want to require the derived forms to implement certain methods of the base form. The easy solution would be to declare abstract methods in the base form. But I can't do that, since the WinForms Designer can't instantiate an abstract form. So, what would be a good alternative to...
2
1576
by: Daniel P. | last post by:
Since multiple inheritance does not exist in C# I would like to be able to subclass the Form and then have other class subclass MyForm. If I do that then the designer will not see my classes as Forms anymore. How can I fix that and have the design behave as MyFinalClass subclasses the Form directly? Thanks!
0
929
by: Graham | last post by:
Hi everyone, I would like to create a base class which inherits from System.Windows.Forms.Form and contains several pure-virtual ("MustOverride") functions. For example: Public MustInherit Class MyInterfaceForm Inherits System.Windows.Forms.Form
17
1197
by: Fabiano Sidler | last post by:
Hi folks! For debugging purposes I tried this: --- snip --- def foo(): pass function = type(foo) class PrintingFunction(function): def __init__(self, func):
14
1627
by: d-42 | last post by:
Hi, Is there any way to make this method inheritable and have it behave appropriately on inherited classes? Using generics? Extension methods? Something else? class baseClass { public static string ClassName() {
6
1775
by: Hicham Mouline | last post by:
Hello, A semi-skeptical colleague is asking me why friendship is not inheritable, specifically: class Base { public: virtual void f() const =0; }; class Derived : public Base {
0
8202
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. ...
1
7959
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...
0
8216
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...
0
6614
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...
1
5710
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...
0
5390
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3865
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2345
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
0
1180
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...

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.