Beispiel #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ChoiceBoxController"/> class.
        /// </summary>
        /// <param name="element">The element representig the related <see cref="ChoiceBox"/></param>
        /// <param name="enabled">True if the <see cref="ChoiceBox"/> is modifiable, false otherwise</param>
        public ChoiceBoxController(ChoiceBox element, bool enabled)
            : base(enabled)
        {
            this.element = element;
            enabledVal   = enabled;

            if (enabled)
            {
                groupPanel = new Panel()
                {
                    Height = 0,
                    Width  = this.Width - (2 * padding)
                };
                Panel checksContainer = new Panel()
                {
                    Width = groupPanel.Width - 40,
                    Dock  = DockStyle.Left
                };
                Panel editContainer = new Panel()
                {
                    Width = 40,
                    Dock  = DockStyle.Right
                };

                groupPanel.Controls.Add(checksContainer);
                groupPanel.Controls.Add(editContainer);

                for (int i = 0; i < element.Fields.Length; i++)
                {
                    RadioButton button = new RadioButton()
                    {
                        Enabled = enabled,
                        Top     = groupPanel.Height,
                        Font    = new Font("Tahoma", 8, FontStyle.Regular),
                        Text    = element.Fields[i].Name,
                        Width   = checksContainer.Width
                    };
                    RoundedButton editButton = new RoundedButton()
                    {
                        Width            = 38,
                        Height           = button.Height - 2,
                        Top              = groupPanel.Height,
                        Left             = 1,
                        BackColor        = Color.FromArgb(236, 236, 236),
                        BorderColor      = Color.FromArgb(146, 146, 146),
                        ClickedBackColor = Color.FromArgb(186, 186, 186),
                        Text             = "edit",
                        Font             = new Font("Tahoma", 8, FontStyle.Regular),
                        ForeColor        = Color.FromArgb(90, 90, 90),
                        BorderSize       = 1,
                        CornerRadius     = 4
                    };

                    groupPanel.Height += button.Height + padding;

                    checksContainer.Controls.Add(button);
                    editContainer.Controls.Add(editButton);

                    button.CheckedChanged += OnCheckedChange;
                    editButton.Click      += new EventHandler(OnEditButtonClick);

                    if (element.SelectedIndex == i)
                    {
                        button.Checked     = true;
                        editButton.Visible = true;
                    }
                    else
                    {
                        editButton.Visible = false;
                    }
                }

                groupPanel.Height -= padding;

                Content     = groupPanel;
                Title       = element.Name;
                Description = element.Description;
            }
            else
            {
                resultPanel = new RoundedPanel {
                    BackColor    = Color.Transparent,
                    BorderColor  = Color.FromArgb(90, 90, 90),
                    BorderSize   = 1,
                    CornerRadius = 4,
                    Dock         = DockStyle.None,
                    Height       = 0
                };

                int buttonMargin = padding;

                FieldController controller = FieldFactory.CreateController(element.Fields[element.SelectedIndex], false);

                RadioButton button = new RadioButton()
                {
                    Checked = true,
                    Enabled = enabled,
                    Font    = new Font("Tahoma", 8, FontStyle.Regular),
                    Left    = resultPanel.CornerRadius + 1,
                    Text    = element.Fields[element.SelectedIndex].Name,
                    Top     = buttonMargin
                };

                buttonMargin += button.Height;
                resultPanel.Controls.Add(button);

                (controller as Control).Top    = buttonMargin;
                (controller as Control).Left   = resultPanel.CornerRadius + 1;
                (controller as Control).Width  = resultPanel.Width - (2 * (resultPanel.CornerRadius + 1));
                (controller as Control).Anchor = AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Top;

                buttonMargin += (controller as Control).Height + padding;

                resultPanel.Controls.Add(controller as Control);
                resultPanel.Height += buttonMargin + (2 * padding);

                Content     = resultPanel;
                Title       = element.Name;
                Description = element.Description;
            }
        }
Beispiel #2
0
 /// <summary>
 /// Overloaded constructor
 /// </summary>
 /// <param name="element">The element representig the related <see cref="ChoiceBox"/></param>
 public ChoiceBoxController(ChoiceBox element)
     : this(element, true)
 {
 }