473,387 Members | 3,810 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,387 software developers and data experts.

Cannot open derived form in design view if the base form is marked 'abstract'.

Hi folks!

I have a BaseForm class that inherits System.Windows.Forms.Form. It has a
property, whose value I need supplied by the class that inherits it. The
BaseForm usees the value supplied into this property in its Load event.

So, I gave the BaseForm and the property 'abstract' modifier, and put the
implementation of the property in the inherited class; say MyForm. However,
when I did this, I no longer can open MyForm in the design view. I'm stuck
if I can't visually design MyForm.... :(

Would appreciate any input, even if it means altogether different way to
accomplish.

thanks!
-Yasutaka

Jul 21 '05 #1
2 2753
Yes, designer won't work with abstract forms.
You should avoid use of abstract keyword (use virtual instead) if you want
to use visual designer.

--
Miha Markic - RightHand .NET consulting & development
miha at rthand com
www.rthand.com

"Yasutaka Ito" <no****@nonexistent.com> wrote in message
news:%2***************@TK2MSFTNGP11.phx.gbl...
Hi folks!

I have a BaseForm class that inherits System.Windows.Forms.Form. It has a
property, whose value I need supplied by the class that inherits it. The
BaseForm usees the value supplied into this property in its Load event.

So, I gave the BaseForm and the property 'abstract' modifier, and put the
implementation of the property in the inherited class; say MyForm. However, when I did this, I no longer can open MyForm in the design view. I'm stuck
if I can't visually design MyForm.... :(

Would appreciate any input, even if it means altogether different way to
accomplish.

thanks!
-Yasutaka

Jul 21 '05 #2
100
Hi Yasutaka Ito,

Yes, you cannot use the deisgner because it cannot create objects of
abstract class.
So, if you want to use the designer what you might want to do is not do
declare the BaseForm class as abstract. Declare the property as virtual
instead of abstract.

Of course you cannot force the inheritors to provide meaningful
implemetation of the property. To workarrond this you can make your default
implemetation to throw and exception. To prevent the base class to be
instantiated make its constructor protected. My tests show it won't mess up
with the designer. If it does leave it public. In your case base calss
cannot be instantiated because it uses Prop in OnLoad and it throws
exception. But the tesigner cannot istantiate it either ;) so we are back to
square one. So, in OnLoad we have to check whether the form is in design
mode or in run-time. This can be check by reading the form's protected
property *DesignMode* and if it returns true - don't read the proerty use
some default value. This check can be done in the property's get accessor,
but since it might can be checked frequently and the Load is called only
once when the form is loading I believe you can save one *if* intruction by
check DesignMode in OnLoad.
like this
class BaseForm: Form
{
.....
public virtual string Prop
{
get
{
throw new NotImplementedException();
}
}

protected BaseForm()
{
}
....
protected override void OnLoad(System.EventArgs e)
{
if(!this.DesignMode)
//read Prop and do something
else
//Use some default value
}
}

This way an exception will be thrown as soon as Prop is used and is not
overriden by an inheritor.
Bare in mind tha the designer instantiate an object (form) of the base class
of the form you actually design. That means that in design mode you cannot
use the Prop's values returned by teh inheritors you can use only some
default value.

HTH
B\rgds
100

"Yasutaka Ito" <no****@nonexistent.com> wrote in message
news:%2***************@TK2MSFTNGP11.phx.gbl...
Hi folks!

I have a BaseForm class that inherits System.Windows.Forms.Form. It has a
property, whose value I need supplied by the class that inherits it. The
BaseForm usees the value supplied into this property in its Load event.

So, I gave the BaseForm and the property 'abstract' modifier, and put the
implementation of the property in the inherited class; say MyForm. However, when I did this, I no longer can open MyForm in the design view. I'm stuck
if I can't visually design MyForm.... :(

Would appreciate any input, even if it means altogether different way to
accomplish.

thanks!
-Yasutaka

Jul 21 '05 #3

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

Similar topics

3
by: tirath | last post by:
Hi all, I have a templated class that derives from a non-templated abstract class. How do I then cast a base class pointer to a <templated> derived class pointer in a generalised fashion? ...
1
by: wooks | last post by:
The schema below describes an interface to a form where the appInterface type is an extension of an abstract type called interface and it contains an appFrame element that is an extension of an...
8
by: Dev | last post by:
Hello, Why an Abstract Base Class cannot be instantiated ? Does anybody know of the object construction internals ? What is the missing information that prevents the construction ? TIA....
11
by: K.K. | last post by:
Suppose I have a class called Vehicle with many fields. Now I make a new class derived from Vehicle called Car. I'd like to make a method to copy the data from a Vehicle instance to a Car instance....
6
by: Edward Diener | last post by:
Since a C++ using declaration isn't allowed in MC++, is there a way to specify that a property, method, event, or field's access can be changed in a derived class, ie. is protected in one class and...
2
by: Yasutaka Ito | last post by:
Hi folks! I have a BaseForm class that inherits System.Windows.Forms.Form. It has a property, whose value I need supplied by the class that inherits it. The BaseForm usees the value supplied...
2
by: Ferdinand Zaubzer | last post by:
Is there any possibility to create a usercontrol deriving from an abstract usercontrol? I could only achieve it by editing the code from "MyControl : System.Windows.Forms.UserControl" to...
3
by: VMI | last post by:
I posted this in the MS aspnet NG and nobody replied. Hopefully, I'll be luckier here... I have VS .net 2003 v1.1 and I'm trying to view some web pages in the designer form. When I try to do this,...
15
by: Bob Johnson | last post by:
I have a base class that must have a member variable populated by, and only by, derived classes. It appears that if I declare the variable as "internal protected" then the base class *can*...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

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.