Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

how to make a Form inherits from another class?

29 views
Skip to first unread message

Anderson Takemitsu Kubota

unread,
Feb 21, 2003, 2:58:48 PM2/21/03
to
Hi all.

Does anybody here know how to make a form with inheritance from another
class?
I tried the following:

namespace zzz

{

/// <summary>

/// Summary description for Form1.

/// </summary>

public class frmInitial : BaseForm

{

And in the baseform:
namespace yyy.Controls

{

/// <summary>

/// Summary description for BaseForm.

/// </summary>

public class BaseForm : System.Windows.Forms.Form

{


But when I open the designer, it returns an error.
Any help?

Thank you.

Anderson Kubota


Luke Boyle

unread,
Feb 21, 2003, 3:06:24 PM2/21/03
to
Anderson,

Unfortunately, the VS.NET Form Designer apparently can't handle the drawing
of forms that are not directly inherited from System.Windows.Forms.Form.

My workaround is to let the form inherit from System.Windows.Forms.Form at
design time, and then switch the code to have it inherit from your base form
just before compile time. It's not an ideal solution, but it works just
fine. I also wrote a macro that will automatically modify the code
automatically. Check out this post for details:

http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&oe=UTF-8&safe=off&threadm
=%23lDgohjxCHA.2604%40TK2MSFTNGP12&rnum=12&prev=/groups%3Fnum%3D20%26hl%3Den
%26lr%3D%26ie%3DUTF-8%26oe%3DUTF-8%26safe%3Doff%26q%3Dauthor%253Aluke%40mara
thondata.com%2BOR%2Bauthor%253Aluke%40NOSPAMmarathondata.com

(Don't forget to copy and paste the entire URL into your browser, since
clicking the link probably won't grab the whole thing.)

Luke


Neelima Godugu

unread,
Feb 21, 2003, 3:13:46 PM2/21/03
to
Visual Inheritance(Form inheritance using the designer) is not supported
with CF.
If you want the designer you have to remove the :BaseForm and add
":System.Windows.Form" to your class. You can toggle between both whenever
you need to use the designer.
HTH
Neelima

"Anderson Takemitsu Kubota" <ander...@br.inter.net> wrote in message
news:e03LjOe...@TK2MSFTNGP09.phx.gbl...

Anderson Takemitsu Kubota

unread,
Feb 21, 2003, 3:25:13 PM2/21/03
to
Thank you all!


"Neelima Godugu" <gnee...@hotmail.com> wrote in message
news:uuyH#We2CH...@TK2MSFTNGP10.phx.gbl...

David So [MS]

unread,
Feb 24, 2003, 6:48:39 PM2/24/03
to
Anderson,

The .netcf form designer doesn't support designing forms that inherit from
subclasses of Form. To work around this you can do something like this

#if designing
public class myForm : Form
#else
public class myForm : myFormSubclass
#endif

Thanks,

David
This posting is provided "AS IS" with no warranties, and confers no rights.

Anderson Takemitsu Kubota

unread,
Feb 25, 2003, 9:24:56 AM2/25/03
to
David,
This is a good idea.
Just one question more: where can I define the constants? (designing)

Thank you.

Anderson

"David So [MS]" <davi...@microsoft.com> wrote in message
news:2LSG18F3CHA.1684@cpmsftngxa06...

Baccarin

unread,
Feb 26, 2003, 11:46:33 PM2/26/03
to
Anderson,

You will need to add this conditional compilation constant (‘designing’)
using your project properties, selecting Configuration Properties / Build /
Conditional Compilation Constants inside VS.NET.

Baccarin.


"Anderson Takemitsu Kubota" <ander...@br.inter.net> escreveu na mensagem
news:O6XxnmN3...@TK2MSFTNGP09.phx.gbl...

Anderson Takemitsu Kubota

unread,
Feb 27, 2003, 9:01:13 AM2/27/03
to
Thanks, Baccarin.
But I just can set for Debug or Release compilation, right? There isn't a
design time constant.
So, all the times I were design, I should set it.

Anderson

"Baccarin" <pe...@pekus.com.br> wrote in message
news:#GBIZCg3...@TK2MSFTNGP12.phx.gbl...

David So [MSFT]

unread,
Feb 27, 2003, 6:45:37 PM2/27/03
to
Anderson,

The following steps would be what's need to get designer support and
inherited form supported in runtime.

1. Bring up the configuration manager by select it from the configuration
drop down in IDE. (It contains Debug, Release, etc.)
2. Select <New> and create a configuration as "Design", you can copy the
settings from the "Debug" configuration.
3. Bring up the project property page and make sure the "Design"
configuration is selected in "Configuration" drop down.
4. Put the compliation constant "DESIGN" into "Conditional Compilation
Constant" together with DEBUG; TRACE;
5. Close the designer.
6. Place the following code in the inherited form

#if DESIGN
public class Form2 : System.Windows.Forms.Form
#else
public class Form2 : Form1
#endif

7. When switch to design mode, make sure the "Design" configuration is set.
8. When deploy/debug/run to device, make sure the "Debug" or "Release"
configuration is set or else you form will not be an inherited form.

This will allows you to easily switch between "Designer Support" and
"Runtime support" for inherited forms.
Note:
The designer support would only means you can add control to the inherited
form but you will not see inherited control from it's parent form.


Add the "designing" compilation constant next to the DEBUG;TRACE

and this should allow you to have design time support and inherit form
support in runtime.

Anderson Takemitsu Kubota

unread,
Feb 28, 2003, 8:21:01 AM2/28/03
to
David,

Your explanation was perfect. It couldn't be better.
This will be very helpful.

Thank you very much.

Anderson Kubota

"David So [MSFT]" <davi...@microsoft.com> wrote in message
news:zWMFapr3...@cpmsftngxa08.phx.gbl...

0 new messages