2013-11-22 5 views
1

구성 요소를 닫고 싶은 클래스가 있습니다. 다음 코드를 기반으로 작동 시키려고합니다.구성 요소 - 하위 클래스 이벤트 C#

문제는 속성 브라우저에서 속성을 편집하고 볼 수 있다는 것입니다. & 테스트 이벤트를 볼 수는 있지만 속성 브라우저에서 채울 수는 없습니다. 코드.

어떻게이 문제를 해결할 수 있습니까? 당신은 비주얼 스튜디오 속성 편집기에서 편집 할 수 있도록

namespace TestComponents 
{ 
    public partial class Test: Component 
    { 
    [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)] 
    public SubClass SubClass { get; set; } 

    public Test() 
    { 
     InitializeComponent(); 
     SubClass = new SubClass(); 
    } 
    } 

    public delegate void TestEventHandler(Object sender, TestEventArgs e); 

    public class TestEventArgs: EventArgs 
    { 
    public Boolean Test { get; set; } 

    public TestEventArgs(Boolean ATest): base() 
    { 
     Test = ATest; 
    } 
    } 

    [TypeConverterAttribute(typeof(System.ComponentModel.ExpandableObjectConverter))] 
    public class SubClass 
    { 
    public Boolean TestProperty { get; set; } 
    public event TestEventHandler TestEvent; 

    protected virtual void OnTestEvent(TestEventArgs e) 
    { 
     if (TestEvent != null) 
     TestEvent(this, e); 
    } 
    } 
} 

답변

0

용의자 속성 편집기, 그것은 복잡한 TestEventArgs 클래스에 관련된 입력을 처리하는 방법을 알 수 없습니다.

당신은 Custom UI Type Editor를 작성에서 모양과 다음 EditorAttribute를 사용하여 사용자 정의 편집기를 지정할 수 있습니다 :

[EditorAttribute(typeof(YourCustomEditor),typeof(System.Drawing.Design.UITypeEditor))] 
+0

하지만 하위 클래스가 아닌 구성 요소 내부에서 직접 이벤트를 선언 할 경우 Visual Studio에서 편집기 속성을 선언하지 않고이 이벤트의 코드를 자동으로 만듭니다. – Ivn

+0

혼란 스럽습니다. 귀하의 코드에 따르면 귀하의 이벤트는 하위 클래스 안에 있습니까? 속성 그리드에서 속성을 표시하는 개체는 무엇입니까? 테스트 또는 하위 클래스? 스크린 샷이 도움이 될 수 있습니다. – Gareth

+0

http://i.stack.imgur.com/utxtR.png – Ivn

1

문제 해결. Component에서 상속 된 서브 클래스 인 경우, Visual Studio는 "서브 클래스 이벤트"를 잘 관리 할 수 ​​있습니다.