C#创建具有自定义属性的基本表单
我遇到了一个小问题,定义的自定义属性值没有以继承的形式存在 我的基本表单中的代码是:C#创建具有自定义属性的基本表单,c#,winforms,base,inheritance,C#,Winforms,Base,Inheritance,我遇到了一个小问题,定义的自定义属性值没有以继承的形式存在 我的基本表单中的代码是: namespace ContractManagement.Forms { public partial class BaseForm : Form { public BaseForm() { InitializeComponent(); } public Boolean DialogForm
namespace ContractManagement.Forms
{
public partial class BaseForm : Form
{
public BaseForm()
{
InitializeComponent();
}
public Boolean DialogForm
{
get
{
return TitleLabel.Visible;
}
set
{
TitleLabel.Visible = value;
CommandPanel.Visible = value;
}
}
protected override void OnTextChanged(EventArgs e)
{
base.OnTextChanged(e);
TitleLabel.Text = Text;
}
}
}
然后以继承这一点的形式,我有:
namespace ContractManagement.Forms
{
public partial class MainForm : Forms.BaseForm
{
public MainForm()
{
InitializeComponent();
}
}
}
出于某种原因,不管我在MainForm中为DialogForm设置了什么,在运行时它会恢复为True
这个网站上还有一篇文章提到了这一点,但我不明白它解释了什么
我还想创建一个允许我隐藏控制框的属性,那么如何将其添加到中?我相信我现在已经做到了:
namespace ContractManagement.Forms
{
public partial class BaseForm : Form
{
private Boolean DialogStyle;
private Boolean NoControlButtons;
public BaseForm()
{
InitializeComponent();
TitleLabel.Visible = DialogStyle = true;
ControlBox = NoControlButtons = true;
}
public Boolean DialogForm
{
get
{
return DialogStyle;
}
set
{
DialogStyle = TitleLabel.Visible = value;
DialogStyle = CommandPanel.Visible = value;
}
}
public Boolean ControlButtons
{
get
{
return NoControlButtons;
}
set
{
NoControlButtons = ControlBox = value;
}
}
protected override void OnTextChanged(EventArgs e)
{
base.OnTextChanged(e);
TitleLabel.Text = Text;
}
}
}
看看这个链接@DJKRAZE——这是我提到的另一篇文章,但我不明白仅仅做上面的事情有什么错。与另一篇文章中的答案相比,我需要对我的代码做哪些不同之处,因为我有两件事要设置。首先,您要存储和/或访问哪些属性和/或值。。在初始化后的链接中,注意链接如何初始化,然后_一些控件名..例如