Short answer
You should add the property to base class of your form, then you can see it in designer when you open the child form:
public class Form1 : BaseForm
{
public Form1()
{
InitializeComponent();
}
}
public class BaseForm : Form
{
//The property is not visible in designer of BaseForm
//But you can see it in designer of Form1
public string SomeProperty {get;set;}
}
The reason behind this behavior
The reason is in the way that designer works. When the designer shows a form at design time, in fact it creates an instance of the base class of the form and shows its properties. So having public class Form1:Form
in designer, what you see in designer is actually an instance of Form
class and the instances of controls which values of properties has been set using using InitializeComponent
method of Form1
and also controls which are added using InitializeComponent
method of Form1
.
Also for user controls, you can not see your custom properties in the designer of your user control, because the properties that you can see in designer of your user control, is properties of it's base class. But when you put an instance of your user control on a form, you will see properties of that instance which is properties of your UserControl1
.
Properties of the root element of your designer are properties of base class of the root element. But the values are exactly those which are set in InitializeComponent
.
To find more information and see an interesting example of how the designer works, you can take a look at this post or this one.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…