.Net CF Form inheritance problem.

G

Guest

Is there any easy way to derive Form class from another Form class, rather then derive it from System.Windows.Form directly? My problem is that Visual Studio designer wouldn't render the form if you derive it from another form which is an abstract class
The "half way" solution I found is to use conditional compilation approach like this

public class MyForm :
#if NETCFDESIGNTIM
System.Windows.Forms.For
#els
MyBaseFor
#endi


.........
#if !NETCFDESIGNTIME
override
#endif public void InitializeComponent(

#if !NETCFDESIGNTIME
base. InitializeComponent()
#endi
......




#if NETCFDESIGNTIM
public class MyBaseForm: System.Windows.Forms.Form
#els
public abstract class MyBaseForm: System.Windows.Forms.Form #endi


#if ! NETCFDESIGNTIM
virtual
#endi
public void InitializeComponent(

........


This is working OK, but I have to manually define and undefine NETCFDESIGNTIME in order to switch between designer and runtime builds. I have seen an article on how to build two versions of the assembly to keep designer happy. One for Design mode and one for .Net CF runtime. I think I should use System.CF.Design.RuntimeAssembly attribute. I just don't know what would be the best way to do it
Any suggestions would be greatly appreciated
Thanks
Pave
 
M

Maarten Struys, eMVP

Since visual form inheritance is not supported it makes most sense to use
conditional compilation as you show in your code snippets. What you could do
to make the process a little easier is the following:

Creating a new configuration in Visual Studio, specifically for "designer
mode". What you would do is the following: Create a new configuration using
Build - Configuration Manager. In the configuration manager dialog box
create a new configuration (e.g. netcfdesigntime), based on the already
existing Debug configuration. When you open your project you now select the
netcfdesigntime configuration when you are designing your (inherited) forms.

Make sure to right click the project file in the solution explorer, select
properties and add a compiler constant for the netcfdesigntime
configuration (in configuration properties - build). For instance you now
can add NETCFDESIGNTIME. Once you want to build a debug or release version,
just change the configuration accordingly, meaning NETCFDESIGNTIME is no
longer defined. In this case you don't have to change the source code or set
/ reset NETCFDESIGNTIME manually.

--
Regards,

Maarten Struys, eMVP
PTS Software bv

www.opennetcf.org | www.dotnetfordevices.com

Pavel Abel said:
Is there any easy way to derive Form class from another Form class, rather
then derive it from System.Windows.Form directly? My problem is that Visual
Studio designer wouldn't render the form if you derive it from another form
which is an abstract class.
The "half way" solution I found is to use conditional compilation approach like this:

public class MyForm :
#if NETCFDESIGNTIME
System.Windows.Forms.Form
#else
MyBaseForm
#endif
{

..........
#if !NETCFDESIGNTIME
override
#endif public void InitializeComponent()
{
#if !NETCFDESIGNTIME
base. InitializeComponent();
#endif
.......

}
}

#if NETCFDESIGNTIME
public class MyBaseForm: System.Windows.Forms.Form
#else
public abstract class MyBaseForm: System.Windows.Forms.Form #endif
{

#if ! NETCFDESIGNTIME
virtual
#endif
public void InitializeComponent()
{
.........
}
}
This is working OK, but I have to manually define and undefine
NETCFDESIGNTIME in order to switch between designer and runtime builds. I
have seen an article on how to build two versions of the assembly to keep
designer happy. One for Design mode and one for .Net CF runtime. I think I
should use System.CF.Design.RuntimeAssembly attribute. I just don't know
what would be the best way to do it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top