473,386 Members | 1,720 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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 4820
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 NotImplementedException, 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 NotImplementedException(); {
#else
public abstract void MyMethod();
#endif

Hope this helps
Jay

"J.Marsch" <je****@ctcdeveloper.com> wrote in message
news:%2****************@TK2MSFTNGP10.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
by: Mark | last post by:
Hi all, quick question, how do I make a define a class as being inheritable only?? Thanks Mark
1
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...
2
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...
1
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...
2
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...
0
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...
17
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
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...
6
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
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...

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.