using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Design;
using System.Windows.Forms.Design;
namespace WindowsFormsApplication12
{
public partial class UserList : UserControl
{
public UserList()
{
InitializeComponent();
}
Control ParentForm;
List<Control> objControlList = new List<Control>();
private void UserList_Load(object sender, EventArgs e)
{
ParentForm = this.Parent;
GetAllControls(ParentForm);
UserControlEditor.PropertyCopyControlList = objControlList;
label1.Text = Convert.ToString(UserControlEditor.PropertyCopyControlList.Count);
}
private void GetAllControls(Control container)
{
foreach (Control c in container.Controls)
{
GetAllControls(c);
if (c is UserList) objControlList.Add(c);
}
}
bool[] objbool = new bool[5];
[Description("Items in the lisbox"), Editor(typeof(UserControlEditor), typeof(UITypeEditor))]
public bool[] NoOfUserlistsOnForm
{
get
{
return objbool;
}
set
{
objbool = value;
{
for (int i = 0; i < (objControlList.Count); i++)
{
if (objbool[i] != false)
{
listBox1.Items.Add(objControlList[i].Name);
}
}
}
}
}
}
class UserControlEditor : UITypeEditor
{
public UserControlEditor()
{
}
public static List<Control> CopyControlList = new List<Control>();
public static List<Control> PropertyCopyControlList
{
get { return CopyControlList; }
set { CopyControlList = value; }
}
public override UITypeEditorEditStyle GetEditStyle(System.ComponentModel.ITypeDescriptorContext context)
{
return UITypeEditorEditStyle.DropDown;
}
public override object EditValue(System.ComponentModel.ITypeDescriptorContext context, IServiceProvider provider, object value)
{
IWindowsFormsEditorService frmsvr = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));
if (frmsvr == null)
return null;
CheckedListBox Clbox = new CheckedListBox();
for (int i = 0; i < PropertyCopyControlList.Count; i++)
{
Clbox.Items.Add(PropertyCopyControlList[i].Name);
}
var es = provider.GetService(typeof(System.Windows.Forms.Design.IWindowsFormsEditorService)) as System.Windows.Forms.Design.IWindowsFormsEditorService;
es.DropDownControl(Clbox);
if (es != null)
{
var data = value as bool[];
if (data != null)
{
for (int i = 0; i < Math.Min(data.Length, Clbox.Items.Count); i++)
{
Clbox.SetItemChecked(i, data[i]);
}
}
es.DropDownControl(Clbox);
}
var result = new bool[5];
for (int i = 0; i < Clbox.Items.Count; i++)
{
result[i] = Clbox.GetItemChecked(i);
}
return result;
}
}
}