1
我有這樣定義的用戶控件:我想從設計師做groupBox1.Text直接訪問,所以我去了明顯的解決方案爲什麼winforms設計器忽略重寫屬性的屬性?
public partial class FooControl : UserControl
{
private System.Windows.Forms.GroupBox groupBox1;
...
,並在我的FooControl創建了以下屬性:
[CategoryAttribute("Appearance"), DescriptionAttribute("The text associated with this control.")]
public string Text
{
get { return groupBox1.Text; }
set { groupBox1.Text = value;}
}
,因爲文字是我的超類中已經定義這不起作用(事實上,這是一個有點,因爲可瀏覽= false屬性的黑暗,但我終於找到它):
public class UserControl : ContainerControl
{
[Bindable(false)]
[EditorBrowsable(EditorBrowsableState.Never)]
[Browsable(false)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public override string Text { get; set; }
一個簡單的解決方法是使用「Text2」而不是「Text」作爲屬性名稱,在這種情況下,一切正常。但是,如果我使用覆蓋或新建,我的代碼編譯(和工程),但我的文本屬性在設計器中不可見。
這種行爲的原因是什麼?是否有解決方法(除了使用其他屬性名稱)?
VS你上哪個版本? – JohnIdol 2009-10-29 15:13:31
vs2008 v9.0.30729.1 SP – Brann 2009-10-30 10:14:49