2009-10-29 2 views
1

I는 다음과 같이 정의 된 사용자 컨트롤이있어 :winforms 디자이너가 재정의 된 속성의 특성을 무시하는 이유는 무엇입니까?

public partial class FooControl : UserControl 
    { 
     private System.Windows.Forms.GroupBox groupBox1; 
     ... 

내가 디자이너에서 직접 그래서 나는 확실한 해결책에 들어갑니다 groupBox1.Text에 액세스 할 수 있도록하고 싶었을 내 FooControl에 다음과 같은 속성을 만든 :

 [CategoryAttribute("Appearance"), DescriptionAttribute("The text associated with this control.")] 
     public string Text 
     { 
      get { return groupBox1.Text; } 
      set { groupBox1.Text = value;} 
     } 

텍스트가 이미 내 슈퍼 클래스에 정의되어 있기 때문에이 작동하지 않습니다는 (사실, 그건 때문에 탐색이 = 거짓 속성의 어둠 속에서 조금,하지만 난 결국 그것을 발견) :

public class UserControl : ContainerControl 
    { 

     [Bindable(false)] 
     [EditorBrowsable(EditorBrowsableState.Never)] 
     [Browsable(false)] 
     [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] 
     public override string Text { get; set; } 

쉬운 해결 방법은 "Text"대신 "Text2"를 속성 이름으로 사용하는 것입니다.이 경우 모든 것이 올바르게 작동합니다.

그러나 override 나 new를 사용하면 코드가 컴파일되고 작동하지만 디자이너에서 Text 속성을 볼 수 없습니다.

이 동작의 이유는 무엇입니까? 다른 속성 이름을 사용하는 것 이외의 다른 해결 방법이 있습니까?

+0

VS 버전은 무엇입니까? – JohnIdol

+0

vs2008 v9.0.30729.1 SP – Brann

답변

1

누가 이익을 얻을 수 나는 아주 오래된 질문입니다 알고 당신은 이미이 문제를 해결 한 수 있지만, 나는이 작품 것을 발견하고 난 누군가를 위해 그것을 게시하고 싶었 :

public partial class FooControl : UserControl 
{ 
    string m_text; 

    [CategoryAttribute("Appearance"), DescriptionAttribute("The text associated with this control.")] 
    [Bindable(true)] 
    [EditorBrowsable(EditorBrowsableState.Always)] 
    [Browsable(true)] 
    [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)] 
    public override string Text 
    { 
     get { return m_text; } 
     set 
     { 
      m_text = value; 
      groupBox1.Text = m_text; 
     } 
    } 

    public FooControl() 
    { 
     InitializeComponent(); 
    } 
} 

주, 나는 Visual Studio 2008에서 위 코드를 테스트하지는 않았지만 문제없이 작동해야합니다.

관련 문제