처음에는 List<T>
대신 Collection<Control>
을 사용합니다. 목록은 종종 효과가 있지만 원하지 않는 방식으로 컬렉션을 노출합니다.
기존 컨트롤을 가져 오려면 LoadValues
오버라이드에서 context.Container.Components
을 조사해야합니다. (호스트 양식 자체 및 구성 요소 포함)이 있으므로 필터를 필터링해야 할 가능성이 큽니다. 확실한 한 가지는 구성 요소 (예 : DataGridViewColumns
및 TabPages
)를 제거하는 것입니다. 목록 또는 컨트롤 모음으로 이동하지 않을 것입니다. 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](https://i.stack.imgur.com/Z95i3.jpg)
, 당신은 자격이 제어 대화 스타일을 표시하고 선택하는 사용자에 대한 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
.NET 4의 새로운 기능은 해당 답변의 유효성에 영향을 미칩니다. –
그 대답에는 .NET Framework 3.5에없는 일부 클래스가 있습니다. 이 중 하나는 System.Collections.ObjectModel.ObservableCollection –