Exemplo n.º 1
0
        private static void GenerateClassControls(object obj, PropertyInfo[] properties, ClassForm form,
            int biggestName)
        {
            int latestY = 0;
            var listOfIndexes = new List<int>();

            for (int n = 0; n < properties.Length; n++)
            {
                var propertyInfo = properties[n];

                var attribute = propertyInfo.GetCustomAttribute(typeof(FormIgnoreAttribute)) as FormIgnoreAttribute;

                if(attribute != null)
                    continue;

               listOfIndexes.Add(n);

                var label = new Label
                {
                    Text = propertyInfo.Name,
                    Width = propertyInfo.Name.Length * Config.PixelPerCharacter,
                    Location = new Point(Config.FormMargin, Config.ControlMargin + latestY)
                };
                form.Controls.Add(label);
                var control = ControlFactory.GetControlFromProperty(obj, propertyInfo, Config);
                control.Location = new Point(biggestName * Config.PixelPerCharacter + Config.FormMargin, label.Location.Y);
                form.Controls.Add(control);
                latestY = control.Location.Y + control.Height;
            }

            form.ListOfIndex = listOfIndexes;
        }
Exemplo n.º 2
0
        public static ClassForm GenerateWinForm(Type type, object obj = null)
        {
            var form = new ClassForm(type, obj);

            form.Height = 0;

            if (obj == null)
            {
                obj = Activator.CreateInstance(type);
            }

            LoadAttributs(type, form);

            var properties  = type.GetProperties();
            var longestName = properties.Length > 0 ? properties.Max(p => p.Name.Length) : 0;

            GenerateControls(type, obj, properties, form, longestName);

            var formWidth = GetFormWidth(longestName, type, form);

            if (formWidth < Config.MinimumFormWidth)
            {
                formWidth = Config.MinimumFormWidth;
            }

            form.Height = GetFormHeight(form);
            form.Width  = formWidth;
            form.Controls[1].Location = new Point(form.Width - form.Controls[0].Width * 2 - Config.FormMargin, form.Height - 75);
            form.Controls[0].Location = new Point(form.Width - form.Controls[0].Width - Config.FormMargin, form.Height - 75);

            return(form);
        }
Exemplo n.º 3
0
        public static ClassForm GenerateWinForm(Type type, object obj = null)
        {
            var form = new ClassForm(type,obj);
            form.Height = 0;

            if (obj == null)
            {
                obj = Activator.CreateInstance(type);
            }

            LoadAttributs(type, form);

            var properties = type.GetProperties();
            var longestName = properties.Length > 0 ? properties.Max(p => p.Name.Length) : 0;

            GenerateControls(type,obj, properties, form, longestName);

            var formWidth = GetFormWidth(longestName, type,form);

            if (formWidth < Config.MinimumFormWidth)
                formWidth = Config.MinimumFormWidth;

            form.Height = GetFormHeight(form);
            form.Width = formWidth;
            form.Controls[1].Location = new Point(form.Width - form.Controls[0].Width*2 - Config.FormMargin ,form.Height - 75);
            form.Controls[0].Location = new Point(form.Width - form.Controls[0].Width - Config.FormMargin, form.Height - 75);

            return form;
        }
Exemplo n.º 4
0
        private static void GenerateValueControls(Type type, object obj, ClassForm form)
        {
            var control = ControlFactory.GetControlFromValue(type, obj, Config);

            control.Location = new Point(Config.FormMargin, Config.FormMargin);
            form.Controls.Add(control);
        }
Exemplo n.º 5
0
 private static int GetFormWidth(int longestName, Type type, ClassForm form)
 {
     if (type.IsValueType || type == typeof(string))
     {
         return(form.Controls[2].Width + Config.FormMargin * 2);
     }
     else
     {
         return(longestName * Config.PixelPerCharacter + Config.DefaultControlWidth + Config.FormMargin * 2);
     }
 }
Exemplo n.º 6
0
        private static void LoadAttributs(Type objType, ClassForm form)
        {
            var formAttribute = objType.GetCustomAttribute(typeof(FormAttribute), true) as FormAttribute;

            if (formAttribute != null)
            {
                form.Text = formAttribute.Text;
                if (formAttribute.Height > 0)
                {
                    form.Height = formAttribute.Height;
                }
            }
        }
Exemplo n.º 7
0
        private static int GetFormHeight(ClassForm form)
        {
            if (form.Height > 39)
            {
                return(form.Height);
            }

            var height = 0;

            for (int n = 0; n < form.Controls.Count; n++)
            {
                height += form.Controls[n].Height;
            }

            return(height + Config.FormMargin + 20);
        }
Exemplo n.º 8
0
 private static void LoadAttributs(Type objType, ClassForm form)
 {
     var formAttribute = objType.GetCustomAttribute(typeof (FormAttribute), true) as FormAttribute;
     if (formAttribute != null)
     {
         form.Text = formAttribute.Text;
         if (formAttribute.Height > 0)
         {
             form.Height = formAttribute.Height;
         }
     }
 }
Exemplo n.º 9
0
 private static int GetFormWidth(int longestName, Type type, ClassForm form)
 {
     if (type.IsValueType || type == typeof (string))
     {
         return form.Controls[2].Width + Config.FormMargin*2;
     }
     else
     {
         return longestName * Config.PixelPerCharacter + Config.DefaultControlWidth + Config.FormMargin * 2;
     }
 }
Exemplo n.º 10
0
        private static int GetFormHeight(ClassForm form)
        {
            if (form.Height > 39)
            {
                return form.Height;
            }

            var height = 0;
            for (int n = 0; n < form.Controls.Count; n++)
            {
                height += form.Controls[n].Height;
            }

            return height + Config.FormMargin + 20;
        }
Exemplo n.º 11
0
 private static void GenerateValueControls(Type type, object obj, ClassForm form)
 {
     var control = ControlFactory.GetControlFromValue(type, obj, Config);
     control.Location = new Point(Config.FormMargin,Config.FormMargin);
     form.Controls.Add(control);
 }
Exemplo n.º 12
0
 private static void GenerateControls(Type type, object obj, PropertyInfo[] properties, ClassForm form, int biggestName)
 {
     if (type.IsValueType || type == typeof(string))
     {
         GenerateValueControls(type, obj, form);
     }
     else
     {
         GenerateClassControls(obj, properties,form,biggestName);
     }
 }
Exemplo n.º 13
0
 private static void GenerateControls(Type type, object obj, PropertyInfo[] properties, ClassForm form, int biggestName)
 {
     if (type.IsValueType || type == typeof(string))
     {
         GenerateValueControls(type, obj, form);
     }
     else
     {
         GenerateClassControls(obj, properties, form, biggestName);
     }
 }
Exemplo n.º 14
0
        private static void GenerateClassControls(object obj, PropertyInfo[] properties, ClassForm form,
                                                  int biggestName)
        {
            int latestY       = 0;
            var listOfIndexes = new List <int>();

            for (int n = 0; n < properties.Length; n++)
            {
                var propertyInfo = properties[n];

                var attribute = propertyInfo.GetCustomAttribute(typeof(FormIgnoreAttribute)) as FormIgnoreAttribute;

                if (attribute != null)
                {
                    continue;
                }

                listOfIndexes.Add(n);

                var label = new Label
                {
                    Text     = propertyInfo.Name,
                    Width    = propertyInfo.Name.Length * Config.PixelPerCharacter,
                    Location = new Point(Config.FormMargin, Config.ControlMargin + latestY)
                };
                form.Controls.Add(label);
                var control = ControlFactory.GetControlFromProperty(obj, propertyInfo, Config);
                control.Location = new Point(biggestName * Config.PixelPerCharacter + Config.FormMargin, label.Location.Y);
                form.Controls.Add(control);
                latestY = control.Location.Y + control.Height;
            }

            form.ListOfIndex = listOfIndexes;
        }