1

디자인 타임에 기존 컨트롤의 컬렉션을 선택합니다 내 사용자 정의 컨트롤을 배치 한 양식의 기존 컨트롤 인스턴스 현재 Visual Studio에서는 새로운 컨트롤을 추가 할 수 있지만 기존 컨트롤은 선택할 수없는 편집기를 보여줍니다.C#의 VS2008 쇼 편집기 내 사용자 컨트롤의 다음 속성이

나는 비슷한 질문과 답을 발견하지만,이 솔루션은 사용자 정의 편집기는 .NET 프레임 워크 4.0을 사용하여 설계, 그리고 나는 현재 3.5 있습니다 Design-time editor support for controls collection

기본 편집기가 거기를, 또는 내가 하나를 구축해야 ?

+0

.NET 4의 새로운 기능은 해당 답변의 유효성에 영향을 미칩니다. –

+0

그 대답에는 .NET Framework 3.5에없는 일부 클래스가 있습니다. 이 중 하나는 System.Collections.ObjectModel.ObservableCollection –

답변

0

처음에는 List<T> 대신 Collection<Control>을 사용합니다. 목록은 종종 효과가 있지만 원하지 않는 방식으로 컬렉션을 노출합니다.

기존 컨트롤을 가져 오려면 LoadValues 오버라이드에서 context.Container.Components을 조사해야합니다. (호스트 양식 자체 및 구성 요소 포함)이 있으므로 필터를 필터링해야 할 가능성이 큽니다. 확실한 한 가지는 구성 요소 (예 : DataGridViewColumnsTabPages)를 제거하는 것입니다. 목록 또는 컨트롤 모음으로 이동하지 않을 것입니다. TableLayoutPanels와 같은 다른 것들도 제거하려고합니다. 원하는 경우

protected override void LoadValues(System.ComponentModel.ITypeDescriptorContext context, System.IServiceProvider provider, object value) 
{ 

    bool bAdd = true; 
    Control thisCtl = null; 

    Collection<Control> tCollection = (Collection<Control>)value; 

    foreach (object obj in context.Container.Components) { 
     //Cycle through the components owned by the form in the designer 
     bAdd = true; 

     // exclude other components - this weeds out DataGridViewColumns which 
     // can only be used by a DataGridView 
     if (obj is Control) { 
      thisCtl = (Control)obj; 

      if (ExcludeForm) { 
       bAdd = !(thisCtl is Form); 
      } 

      // custom exclude list 
      if ((typeExclude != null) && (typeExclude.Count > 0)) { 
       if (typeExclude.Contains(thisCtl.GetType)) { 
        bAdd = false; 
       } 
      } 

      bool bCheck = false; 
      int ndx = 0; 
      if (bAdd) { 
       bCheck = tCollection.Contains(thisCtl); 

       ndx = myCtl.Items.Add(new ListItem(thisCtl)); 
       myCtl.SetItemChecked(ndx, bCheck); 
      } 
     } 

    } 

} 

enter image description here

, 당신은 자격이 제어 대화 스타일을 표시하고 선택하는 사용자에 대한 CheckedListBox를 사용할 수 있습니다

이 버전은 기본 드롭 다운에 대한 몇 가지 구성 요소와 컨트롤을 필터링 통제 수단. CodeProject Selecting Form's Controls at Design Time에 대한 자세한 내용을 다루는 기사가 있습니다.

그것은 VB에 있지만 쉽게 아주 쉽게 (내가 쓴, 그래서 바이어스 할 수있다)와 같은 짐승을 구현할 수 있습니다 : 그냥 다른를 사용하여,

ExampleDropDownControlCollectionUIEditor : ControlCollectionDropDownUIEditor 
{ 
    public ExampleDropDownControlCollectionUIEditor() : base() 
    { 
     base.ExcludeForm = true; 

     base.CheckControlWidth = 200; 

     base.typeExclude.Add(typeof(RadioButton)); 
     base.typeExclude.Add(typeof(Label)); 
    } 
} 

대화 형식은 간단합니다 기본 클래스, ControlCollectionDialogUIEditor

+0

예, 저는 이것이 이전의 질문이라는 것을 알고 있습니다. UI 편집자와 비슷하지만 아직 답을 찾지 못했습니다. – Plutonix

+0

많은 감사합니다 @Plutonix, 나는 거의이 질문에 대한 답변을 얻을 수있는 희망을 잃었 : '(나는 그것을 시도합니다 :) –