我有一个winforms列表
mainWinform
winform1
winform2
winform3 ...
winform1
,winform2
和winform3
继承mainWinform
设计
我设置了一些winform
,如:
winform1
:
maximizeBox = false
FormBorderStyle to Sizable
winform2
:
maximizeBox = true
FormBorderStyle to fixed
由于我继承自mainWinform
,我可以设置每个winform
设置maximizeBox = true
甚至FormBorderStyle to Sizable
的{{1}},mainWinform
已将其设为winform1
maximizeBox = false
?
答案 0 :(得分:1)
要阻止继承的表单覆盖父级设置,您可以尝试覆盖父表单类中的OnStyleChanged
:
protected override void OnStyleChanged(EventArgs e)
{
if (this.MaximizeBox!=true) this.MaximizeBox = true;
base.OnStyleChanged(e);
}
答案 1 :(得分:0)
您必须在继承的form
的构造函数中设置这些属性。例如:
public winform
{
//in this way you can inherit parent form properties and set them to child form
this.MaximizeBox = base.MaximizeBox;
this.FormBorderStyle = base.FormBorderStyle;
//or if you want to set it something else, then do like this
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Sizable;
}
您可以根据需要更改值。但是你必须将代码放在构造函数中。