Пример #1
0
        private int PopulateComponentSide()
        {
            int maxHeight = 0;

            foreach (Control control in ComponentControls)
            {
                if (control is TextBox)
                {
                    FocusHelper.Remove((TextBox)control);
                }

                this.Controls.Remove(control);
            }
            ComponentControls.Clear();
            Point pos = pictureComponent.Location;

            labelComponentName.Left         = pictureComponent.Right + Gap;
            textBoxComponentEntityName.Left = labelComponentName.Left;
            pos.Offset(0, pictureEntity.Height + Gap);
            List <string> allComponentProperties = new List <string>();

            if (ComponentToEdit != null)
            {
                textBoxComponentEntityName.Text = ComponentToEdit.Name;

                foreach (var prop in ComponentToEdit.Properties)
                {
                    allComponentProperties.Add(string.Format("{0}  ({1})", prop.PropertyName, prop.RepresentedProperty.Type));
                }

                for (int i = 0; i < ComponentToEdit.Properties.Count; i++)
                {
                    pos.Y = PropertyLabels[i].Top;
                    var      prop  = ComponentToEdit.Properties[i];
                    ComboBox combo = new ComboBox();
                    combo.Location = pos;
                    combo.Items.AddRange(allComponentProperties.ToArray());
                    combo.Text = string.Format("{0}  ({1})", prop.PropertyName, prop.RepresentedProperty.Type);
                    //label.Text = string.Format("{0}  ({1})", prop.Name, prop.Type);
                    this.Controls.Add(combo);
                    pos.Offset(0, (int)combo.Height + Gap + 2);
                    ComponentControls.Add(combo);
                }
            }
            else
            {
                labelComponentName.Text = "New Component";
                string[] types = new string[] { "string", "int", "bool", "double", "DateTime" };

                // Textboxes to allow user to specify new component properties
                for (int i = 0; i < NewComponent.Properties.Count; i++)
                {
                    var prop = NewComponent.Properties[i];
                    pos.Y = PropertyLabels[i].Top;
                    TextBox tbName = new TextBox();
                    tbName.Text     = prop.Name;
                    tbName.Location = pos;
                    tbName.Width    = 100;
                    ComponentControls.Add(tbName);
                    this.Controls.Add(tbName);
                    FocusHelper.Add(tbName);

                    Point    posType    = new Point(pos.X + tbName.Width + Gap, pos.Y);
                    ComboBox comboTypes = new ComboBox();
                    comboTypes.Items.AddRange(types);

                    if (!types.Contains(prop.Type))
                    {
                        comboTypes.Items.Add(prop.Type);
                    }

                    comboTypes.Text     = prop.Type;
                    comboTypes.Location = posType;
                    comboTypes.Width    = 60;
                    ComponentControls.Add(comboTypes);
                    this.Controls.Add(comboTypes);
                    pos.Offset(0, (int)tbName.Height + Gap + 2);
                }
            }
            return(pos.Y);
        }