private static List <LayoutableGroup> FindUserGroups(Control declaringControl) { Dictionary <String, LayoutableGroup> dictionary = new Dictionary <String, LayoutableGroup>(); FieldInfo[] fis = declaringControl.GetType().GetFields( BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance); foreach (FieldInfo fi in fis) { Object[] attr = fi.GetCustomAttributes(typeof(IFixedLayoutGroup), true); foreach (Object o in attr) { Control c = (Control)fi.GetValue(declaringControl); IFixedLayoutGroup lg = (IFixedLayoutGroup)o; if (!dictionary.ContainsKey(lg.GroupId)) { dictionary[lg.GroupId] = new LayoutableGroup(VBoxLayoutType.Instance, new ControlAdapter(null, c)); } else { LayoutableGroup l = dictionary[lg.GroupId]; AbstractLayoutable asl = new ControlAdapter(null, c); if (l.Controls.Contains(asl)) { throw new Exception("MultipleDefinition"); } dictionary[lg.GroupId].Add(VBoxLayoutType.Instance, asl); } if (lg.CustomLayoutControl != null) { ICustomLayoutControl clc = (ICustomLayoutControl)Activator.CreateInstance(lg.CustomLayoutControl); clc.DeclaringControl = declaringControl; dictionary[lg.GroupId].CustomLayoutControl = clc; } } } List <LayoutableGroup> tmp = new List <LayoutableGroup>(); foreach (LayoutableGroup lg in dictionary.Values) { tmp.Add(lg); } return(tmp); }
private static List <ControlAdapter> CreateControlAdapters(Control declaring, Control control) { List <ControlAdapter> res = new List <ControlAdapter>(); foreach (Control c in control.Controls) { ControlAdapter ca = null; FieldInfo fi = ReflectiveControlSearch(declaring, c); if (c is Panel) { Object[] o = fi.GetCustomAttributes(typeof(LayoutAttribute), false); if (o.Count() > 0) { LayoutAttribute la = (LayoutAttribute)o[0]; ca = new PanelAdapter(null, la.LayoutManager, (Panel)c); } else { ca = new ControlAdapter(null, c); } } else { ca = new ControlAdapter(null, c); } Object[] hfa = fi.GetCustomAttributes(typeof(HorizontalFixedAttribute), false); if (hfa.Count() > 0) { ca.HorizontalFix = true; } hfa = fi.GetCustomAttributes(typeof(VerticalFixedAttribute), false); if (hfa.Count() > 0) { ca.VerticalFix = true; } ca.VirtualX = c.Location.X; ca.VirtualY = c.Location.Y; ca.VirtualWidth = c.Width; ca.VirtualHeight = c.Height; res.Add(ca); } return(res); }