Beispiel #1
0
        /// <summary>
        /// 根据Type来生成控件
        /// </summary>
        private void BuildControlForType(TypeAndInterfaceArr typeAndInterface)
        {
            Type type = typeAndInterface.ClassType;

            //PropertyInfo[] properties = null;

            MemberInfo[] memberInfos = null;

            #region GetProperties
            if (IsStatic)
            {
                memberInfos = type.GetMembers(
                    BindingFlags.Static |
                    BindingFlags.Public |
                    BindingFlags.GetProperty |
                    BindingFlags.SetProperty |
                    BindingFlags.InvokeMethod);
                //properties = type.GetProperties(
                //     BindingFlags.Static |
                //     BindingFlags.Public |
                //     BindingFlags.GetProperty |
                //     BindingFlags.SetProperty);
            }
            else
            {
                memberInfos = type.GetMembers(
                    BindingFlags.Instance |
                    BindingFlags.Public |
                    BindingFlags.GetProperty |
                    BindingFlags.SetProperty |
                    BindingFlags.InvokeMethod);
                /////取当前类的属性
                //properties = type.GetProperties(
                //     BindingFlags.Instance |
                //     BindingFlags.Public |
                //     BindingFlags.GetProperty |
                //     BindingFlags.SetProperty);
                /////取当前类的属性
                //properties = type.GetProperties(
                //     BindingFlags.Instance |
                //     BindingFlags.Public |
                //     BindingFlags.GetProperty |
                //     BindingFlags.SetProperty |
                //     BindingFlags.DeclaredOnly);

                /////取派生类的属性
                //PropertyInfo[] baseProperties = type.BaseType.GetProperties(
                //     BindingFlags.Instance |
                //     BindingFlags.Public |
                //     BindingFlags.GetProperty |
                //     BindingFlags.SetProperty |
                //     BindingFlags.DeclaredOnly);

                /////将dedaoshu得到的属性合成一个数组
                //PropertyInfo[] tempNew = new PropertyInfo[properties.Length + baseProperties.Length];
                //Array.Copy(properties, tempNew, properties.Length);
                //Array.Copy(baseProperties, 0, tempNew, properties.Length, baseProperties.Length);
                //properties = tempNew;
            }
            #endregion

            List <AutoAttributeData> attList = new List <AutoAttributeData>();
            //利用反射得到属性中的定制特性 by lisuye on 2008年5月29日

            //foreach类型里的所有属性是否有定制特性
            foreach (MemberInfo info in memberInfos)
            {
                object[] propertyPadValues = info.GetCustomAttributes(_autoAttributeType, true);
                if (propertyPadValues.Length <= 0)
                {
                    continue;//无定制特性
                }

                //foreach单个属性里的定制特性,Add到attList中
                foreach (AutoLayoutPanelAttribute att in propertyPadValues)
                {
                    attList.Add(new AutoAttributeData(info, att));
                }
            }
            //根据定制特性绘制groupbox控件 by lisuye on 2008年5月29日
            //如果attList.Count小于或等于0的话证明该类型没有定制特性
            if (attList.Count > 0)
            {
                ///根据AutoAttributeData集合获得GroupAttsData集合
                SortedDictionary <int, GroupAttsData> groupBoxList = ToGroupDatas(attList);

                if (groupBoxList != null)
                {
                    foreach (var pair in groupBoxList)
                    {
                        //设置GroupBox的时候,则需要将groupBox的相关属性放在第个组的第一项(规定)
                        AutoAttributeData lastAutoAtt = pair.Value.AutoAttributeDatas[0];
                        bool   isGroupDockTop         = lastAutoAtt.Attribute.GroupBoxDockTop; //当前的组合框是否要置顶
                        string groupText = lastAutoAtt.Attribute.GroupBoxUseWinStyleText;      //当前的组合框的显示文本
                        bool   useGroup  = lastAutoAtt.Attribute.GroupBoxUseWinStyle;
                        //创建groupbox
                        GroupBoxEx box = CreateGroup(pair.Value);

                        //处理当需要将Group置为Dock.Top时的办法(如果置控件的Dock属性是无效的)
                        if (isGroupDockTop)
                        {
                            box.Dock = DockStyle.Top;
                        }
                        //处理控件的语言文本
                        if (!string.IsNullOrEmpty(groupText))
                        {
                            if (box.InnerGroupBox != null)
                            {
                                //获得语言文本
                                box.InnerGroupBox.Text = GetLanguageText(
                                    AutoLayoutPanelXmlDocument.Singler, groupText);
                            }
                        }
                        this.Controls.Add(box);
                    }
                }
            }//if
        }
Beispiel #2
0
 protected internal virtual ValueControl CreateValueControl(AutoAttributeData data, GroupBoxEx group)
 {
     return(new ValueControl(data, group));
 }