C# - 如何在设计器中更改属性的默认值? [英] C# - how do I change default value of property in designer?
本文介绍了C# - 如何在设计器中更改属性的默认值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在用户控件中,我有一个属性Text Text,其定义如下:
In a user control I have a property Text Text with definition as follows :
string text;
[Browsable(true), EditorBrowsable(EditorBrowsableState.Always)]
public override string Text
{
get
{
return text;
}
set
{
this.text = value;
this.Invalidate();
}
}
我将此usercontrol添加到表单并在Properties选项卡中编辑了Text属性。
当我这样做时,usercontrol会在其上显示新文本。
然后当我运行它时,usercontrol没有任何文本,只是没有。
我尝试过:
我尝试添加
I added this usercontrol to a form and edited the Text property in the Properties tab.
When I do this the usercontrol shows the new text on it.
Then when I run it , the usercontrol does not have any text , just nothing.
What I have tried:
I have tried adding
DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
以及
along with
[Browsable(true), EditorBrowsable(EditorBrowsableState.Always)]
推荐答案
我刚刚找到解决方案。
对于那些偶然发现此页面的人来说如下:
I just found the solution.
For those who stumble on this page the solution is given below :
string text;
[EditorBrowsable(EditorBrowsableState.Always)]
[Browsable(true)] [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
[Bindable(true)]
public override string Text
{
get
{
return text;
}
set
{
this.text = value;
this.Invalidate();
}
}
这篇关于C# - 如何在设计器中更改属性的默认值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文