示例#1
0
        public void SetTextMargin()
        {
            int maxWidth = 0;

            if (_component != null)
            {
                foreach (PropertyInfo _info in _component.GetType().GetProperties())
                {
                    if (_info.IsDefined(typeof(IceComponentPropertyAttribute), true))
                    {
                        object[] attributes =
                            _info.GetCustomAttributes(
                                typeof(IceComponentPropertyAttribute), false);
                        IceComponentPropertyAttribute attribute = attributes[0] as IceComponentPropertyAttribute;
                        Font font      = this.Font;
                        int  textWidth = 2 + (int)this.CreateGraphics().MeasureString(attribute.FriendlyName, font).Width;
                        // keep the biggest string's width
                        if (textWidth > maxWidth)
                        {
                            maxWidth = textWidth;
                        }
                    }
                }
                for (int i = 0; i < this.Controls.Count; i++)
                {
                    AutoControl control = this.Controls[i] as AutoControl;
                    control.SetFriendlyNameWidth(maxWidth);
                }
            }
        }
示例#2
0
        private void AddNewControl(PropertyInfo _info)
        {
            AutoControl control = null;

            control = CreateCustomAutoControlInstance(_info);
            if (control != null)
            {
                object[] attributes;
                attributes =
                    _info.GetCustomAttributes(
                        typeof(IceComponentPropertyAttribute), false);
                IceComponentPropertyAttribute attribute = attributes[0] as IceComponentPropertyAttribute;
                object value = _info.GetValue(_component, null);
                control.SetFriendlyName(attribute.FriendlyName);
                if (value == null)
                {
                    if (attribute.DefaultValue != null)
                    {
                        control.SetValue(attribute.DefaultValue);
                    }
                    else
                    {
                        control.SetValue(null);
                    }
                }
                else
                {
                    // special case for enums, convert to int first
                    if (value is Enum)
                    {
                        value = (int)value;
                    }
                    control.SetValue(value.ToString());
                }
                //control.BackColor = Color.RoyalBlue;
                control.Location      = new System.Drawing.Point(0, _lastTop);
                control.Size          = new Size(this.Size.Width, control.Size.Height);
                control.Anchor        = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
                control.Tag           = _info;
                control.ValueChanged += ValueChangedEvent;
                this.Controls.Add(control);
                _lastTop += control.Height + _padding;
            }
        }