C#创建具有自定义属性的基本表单 [英] C# Creating a Base Form with Custom Properties
本文介绍了C#创建具有自定义属性的基本表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我遇到了一个小问题,即定义的自定义属性值未保留在继承的形式中.
I am having a small issue where the defined custom property value is not sticking in the inherited form.
我基本形式的代码是:
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;
}
}
}
然后以继承的形式出现:
Then in the form that inherits this I have:
namespace ContractManagement.Forms
{
public partial class MainForm : Forms.BaseForm
{
public MainForm()
{
InitializeComponent();
}
}
}
由于某些原因,尽管我在MainForm中为DialogForm设置了设置,但在运行时它会恢复为True.
For some reason, despite what I set in MainForm for DialogForm, on runtime it reverts back to True.
此网站上还有另一篇文章提到了这一点,但我不明白它的解释.
There is another post on this site which mentions this, but I don't get what it explains.
我还想创建一个允许我隐藏ControlBox的属性,那么如何添加它呢?
I also want to create a property which allows me to hide the ControlBox, so how do I add this in?
推荐答案
我相信我已经完成了:
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;
}
}
}
这篇关于C#创建具有自定义属性的基本表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文