Visual form inheritance at design time

G

GD

Hi,

Some online articles claim that visual form inheritance at design time is
possible using VS.Net 2005 and Compact Framework 2.0. I wonder if anyone has
successfully made it work. Here is my unsuccessful sample code:

//Parent form
public class FormBase : System.Windows.Forms.Form
{
protected Button button1;
protected void button1_Click(object sender, EventArgs e)
{
MessageBox.Show("This is the base form");
}
}

///Child form
public class FormChild : FormBase
{
}

The component in FormBase doesn't show up in FormChild during design time.

Any idea would be appreciated.

GD
 
G

Guest

Is that all the code? If so, then sure, it will fail. You need to have
correct code to start with, so the base Form needs to add the Button to it's
Copntrols collection, set its properties, etc.

The child form must also be in it's own code file. THe designer can only
handle the first designable class in any given code file.

-Chris
 
G

GD

I didn't list all code here. I simply add a form as the base form in a
project, add a button with an event handler on it. Then add another form as
the child form to the project, and replace 'System.Windows.Forms.Form' with
'FormBase', compile the project and click the child form, no base form
component shows up.
 
G

Guest

This is possible but some additional steps need to be taken. You need to set
the custom attribute of your parent form to DesktopCompatible(true). This is
done by selecting your project in Solution Explorer, right mouse click and
select View Class Diagram from the pop up menu. If your parent form class is
not already in the class diagram then drag it from the Solution Explorer and
drop it in the Class Diagram. Select the parent class in the diagram, right
mouse click and select Properties from the drop down menu. In the Properties
- Misc section you will see the Custom Attributes property. Click in the box
to the right of this label and a button will appear. Click the button and
you are presented with a dialog box into which you add a new line
DesktopCompatible(true). Click the OK button and its done. When you view
your child form in the IDE it should display the properties of its parent
form and likewise when you run the application.
 

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