2013-08-21 53 views
1

在屬性包中,對於foo,我看到顯示了WindowsApplication1.foo,並且如何顯示有意義的文本?PropertyBag,類的類在編輯器中顯示,如何刪除它?

在屬性包中,我看到Foo | windowsApplication1.foo。我如何將windowsapplication1.foo更改爲一些有意義的文本? 感謝您的幫助。

static class Program 
    { 
     [STAThread] 
     static void Main() 
     { 

      Application.EnableVisualStyles(); 
      Form form = new Form(); 
      PropertyGrid grid = new PropertyGrid(); 
      grid.Dock = DockStyle.Fill; 
      form.Controls.Add(grid); 
      grid.SelectedObject = new MyType(); 
      Application.Run(form); 


     } 
    } 

class MyType 
{ 
    private Foo foo = new Foo(); 
    [CategoryAttribute("ID"), DescriptionAttribute("Id")] 
    public Foo Foo 
    { 
     get { return foo; } 
     set { } 
    } 
} 

[Editor(typeof(FooEditor),typeof(UITypeEditor))] 
[TypeConverter(typeof(ExpandableObjectConverter))] 

class Foo 
{ 
    private string bar; 
    private string bar2; 
    public string Bar 
    { 
     get { return bar; } 
     set { bar = value; } 
    } 
    public string Bar2 
    { 
     get { return bar2; } 
     set { bar2 = value; } 
    } 

} 

回答

0

如果你只是想顯示的文本,在Foo覆蓋ToString(),你會看到這一點。

[編輯器(typeof運算(FooEditor)的typeof(UITypeEditor的))] [的TypeConverter(typeof運算(ExpandableObjectConverter))]

class Foo 
{ 
    // your implementation 

    public override string ToString() 
    { 
     // Return what you want displayed... 
     return string.Format("Foo: {0} - {1}", this.Bar, this.Bar2); 
    } 
} 

如果你想爲Foo一個更好的編輯器,你需要自定義UITypeEditor。詳情請參閱Getting the Most Out of the .NET Framework PropertyGrid ControlMake Your Components Really RAD with Visual Studio .NET Property Browser

相關問題