示例#1
0
 /// <summary>
 /// Returns a default radiopanel.
 /// This panel will try to fit into the second column,
 /// if not it will take a new line and spread over the whole width.
 /// </summary>
 /// <param name="position">Position of the Panel.</param>
 /// <param name="tag">Tag for the panel, containing data about the RadioButtons.</param>
 /// <returns></returns>
 private Panel CreateRadioPanel(Position position, SingleSelectionList tag)
 {
   Panel panel = new Panel();
   panel.AutoSize = false;
   panel.Tag = tag;
   panel.TabIndex = position.NextTabIndex;
   panel.Name = "radioPanel" + position.TabIndex.ToString();
   bool takeNewLine = false; // needed to know the columnwidth when calculating the expected height
   List<RadioButton> items = new List<RadioButton>(tag.Items.Count);
   for (int i = 0; i < tag.Items.Count; i++)
   {
     RadioButton btn = new RadioButton();
     btn.AutoSize = false;
     btn.TabIndex = position.NextTabIndex;
     btn.Name = "radioButton" + position.TabIndex.ToString();
     btn.Text = tag.Items[i].Evaluate();
     btn.CheckAlign = ContentAlignment.TopLeft;
     btn.Checked = (i == tag.Selected);
     btn.CheckedChanged += _singleSelectionListChange;
     btn.Tag = i;
     SetHelp(btn, tag.Help.Evaluate());
     items.Add(btn);
     // see if we should take a new line (add 30 for the radiobutton and to cover too small measurements)
     btn.Width = (int)(btn.CreateGraphics().MeasureString(btn.Text, btn.Font).Width + 30);
     if (btn.Width > position.WidthColumnTwo)
       takeNewLine = true;
   }
   // we can't calculate the height before, because we don't know the available width (depends on takeNewLine)
   // => second loop is needed
   Position nPos = (Position)position.Clone();
   nPos.LinePosition = 0;
   int width; // values depend on the new line, we can't use Position
   if (takeNewLine)
   {
     width = position.Width - position.Margin;
   }
   else
   {
     width = position.WidthColumnTwo;
   }
   foreach (RadioButton btn in items)
   {
     btn.Location = new Point(0, nPos.LinePosition);
     if (btn.Width > width)  // doesn't fit in the column, we'll have to calculate the height to avoid overlapping controls
     {
       btn.MaximumSize = new Size(width, (int)((double)btn.Width / width * btn.Height + position.LineHeight - btn.Height));
       btn.MinimumSize = btn.MaximumSize;
       btn.AutoSize = true;
       nPos.LinePosition += btn.MaximumSize.Height;
     }
     else
       nPos.LinePosition += nPos.LineHeight;
     panel.Controls.Add(btn);
   }
   panel.Size = new Size(width, nPos.LinePosition);
   // Locate and return the panel
   if (!takeNewLine)
     panel.Location = new Point(position.StartColumnTwo, position.LinePosition);
   else
   {
     position.LinePosition += position.ItemHeight;
     panel.Location = new Point(position.StartColumnOne + position.Margin, position.LinePosition);
   }
   return panel;
 }
示例#2
0
        /// <summary>
        /// Returns a default radiopanel.
        /// This panel will try to fit into the second column,
        /// if not it will take a new line and spread over the whole width.
        /// </summary>
        /// <param name="position">Position of the Panel.</param>
        /// <param name="tag">Tag for the panel, containing data about the RadioButtons.</param>
        /// <returns></returns>
        private Panel CreateRadioPanel(Position position, SingleSelectionList tag)
        {
            Panel panel = new Panel();

            panel.AutoSize = false;
            panel.Tag      = tag;
            panel.TabIndex = position.NextTabIndex;
            panel.Name     = "radioPanel" + position.TabIndex.ToString();
            bool takeNewLine         = false; // needed to know the columnwidth when calculating the expected height
            List <RadioButton> items = new List <RadioButton>(tag.Items.Count);

            for (int i = 0; i < tag.Items.Count; i++)
            {
                RadioButton btn = new RadioButton();
                btn.AutoSize        = false;
                btn.TabIndex        = position.NextTabIndex;
                btn.Name            = "radioButton" + position.TabIndex.ToString();
                btn.Text            = tag.Items[i].Evaluate();
                btn.CheckAlign      = ContentAlignment.TopLeft;
                btn.Checked         = (i == tag.Selected);
                btn.CheckedChanged += _singleSelectionListChange;
                btn.Tag             = i;
                SetHelp(btn, tag.Help.Evaluate());
                items.Add(btn);
                // see if we should take a new line (add 30 for the radiobutton and to cover too small measurements)
                btn.Width = (int)(btn.CreateGraphics().MeasureString(btn.Text, btn.Font).Width + 30);
                if (btn.Width > position.WidthColumnTwo)
                {
                    takeNewLine = true;
                }
            }
            // we can't calculate the height before, because we don't know the available width (depends on takeNewLine)
            // => second loop is needed
            Position nPos = (Position)position.Clone();

            nPos.LinePosition = 0;
            int width; // values depend on the new line, we can't use Position

            if (takeNewLine)
            {
                width = position.Width - position.Margin;
            }
            else
            {
                width = position.WidthColumnTwo;
            }
            foreach (RadioButton btn in items)
            {
                btn.Location = new Point(0, nPos.LinePosition);
                if (btn.Width > width) // doesn't fit in the column, we'll have to calculate the height to avoid overlapping controls
                {
                    btn.MaximumSize    = new Size(width, (int)((double)btn.Width / width * btn.Height + position.LineHeight - btn.Height));
                    btn.MinimumSize    = btn.MaximumSize;
                    btn.AutoSize       = true;
                    nPos.LinePosition += btn.MaximumSize.Height;
                }
                else
                {
                    nPos.LinePosition += nPos.LineHeight;
                }
                panel.Controls.Add(btn);
            }
            panel.Size = new Size(width, nPos.LinePosition);
            // Locate and return the panel
            if (!takeNewLine)
            {
                panel.Location = new Point(position.StartColumnTwo, position.LinePosition);
            }
            else
            {
                position.LinePosition += position.ItemHeight;
                panel.Location         = new Point(position.StartColumnOne + position.Margin, position.LinePosition);
            }
            return(panel);
        }
示例#3
0
 /// <summary>
 /// Builds the specified node to a Panel.
 /// </summary>
 /// <param name="node">Node to build to the Panel.</param>
 /// <param name="position">Defines the positioning parameters.</param>
 /// <returns></returns>
 private Panel BuildToPanel(IConfigurationNode node, Position position)
 {
   Panel panel = new Panel();
   panel.Tag = node == null ? null : node.ConfigObj;
   panel.AutoSize = false;
   panel.Height = 0;
   panel.Width = position.FullWidth;
   panel.Padding = new Padding(0, 0, 0, 0);
   panel.Margin = new Padding(0, 0, 0, 0);
   if (node == null || node.ConfigObj == null)
     return panel; // Return empty panel
   panel.Name = string.Format("{0}_{1}", node.Location, node.ConfigObj);
   // Add heading
   if (node.ConfigObj is ConfigGroup)
   {
     panel.Controls.Add(CreateHeading(position, node.ConfigObj.Text.Evaluate()));
     position.LinePosition += position.LineHeight;
   }
   // Add subcontrols
   foreach (IConfigurationNode subNode in node.ChildNodes)
   {
     if (subNode.ConfigObj.Hidden) continue;
     if (subNode.ConfigObj is ConfigGroup)
     {
       Position pos = (Position) position.Clone();
       pos.StartColumnOne += pos.Indent; // indent the first column
       pos.WidthColumnOne -= pos.Indent; // shorten the width, so it doesn't overlap with column two
       pos.LinePosition = 0; // reset linePosition, this is relative to the new control
       // Make a recursive call to process the group to a Panel
       Panel subPanel = BuildToPanel(subNode, pos);
       subPanel.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
       subPanel.Location = new Point(0, position.LinePosition);
       subPanel.Enabled = !subNode.ConfigObj.Disabled;
       panel.Controls.Add(subPanel);
       position.LinePosition += pos.LinePosition;
     }
     else if (subNode.ConfigObj is ConfigSetting)
     {
       ConfigSetting setting = (ConfigSetting) subNode.ConfigObj;
       setting.OnChangeEvent += _configChangedHandler;
       if (setting is Entry)
       {
         panel.Controls.Add(CreateLabel(position, setting.Text.Evaluate()));
         TextBox txt = CreateTextBox(position, setting.Columns);
         txt.Text = ((Entry) setting).Value;
         txt.Tag = setting;
         SetHelp(txt, setting.Help.Evaluate());
         txt.Enabled = !setting.Disabled;
         panel.Controls.Add(txt);
         position.LinePosition += position.LineHeight + position.Margin;
       }
       else if (setting is LimitedNumberSelect)
       {
         int height;
         panel.Controls.Add(CreateLabel(position, setting.Text.Evaluate(), position.Width, out height));
         panel.Controls.Add(CreateLimitedNumberSelect(position, (LimitedNumberSelect) setting));
         position.LinePosition += height + position.Margin;
       }
       else if (setting is MultipleEntryList)
       {
         panel.Controls.Add(CreateLabel(position, setting.Text.Evaluate()));
         position.LinePosition += position.LineHeight;
         TextBox txt = CreateMultiLineTextBox(position, setting.Rows);
         txt.Tag = setting;
         MultipleEntryList entryList = (MultipleEntryList) setting;
         txt.Lines = new string[entryList.Lines.Count];
         for (int i = 0; i < txt.Lines.Length; i++)
           txt.Lines[i] = entryList.Lines[i];
         SetHelp(txt, setting.Help.Evaluate());
         txt.Enabled = !setting.Disabled;
         panel.Controls.Add(txt);
         position.LinePosition += txt.Height + position.Margin;
       }
       else if (setting is MultipleSelectionList)
       {
         int lblHeight;
         panel.Controls.Add(CreateLabel(position, setting.Text.Evaluate(), position.WidthColumnOne,
                                        out lblHeight));
         position.LinePosition += lblHeight + position.Margin;
         CheckedListBox chk = CreateCheckedListBox(position);
         MultipleSelectionList list = ((MultipleSelectionList) setting);
         for (int i = 0; i < list.Items.Count; i++)
           chk.Items.Add(list.Items[i], list.SelectedIndices.Contains(i));
         chk.Enabled = !setting.Disabled;
         panel.Controls.Add(chk);
         position.LinePosition += chk.Height + position.Margin;
       }
       else if (setting is NumberSelect)
       {
         int height;
         panel.Controls.Add(CreateLabel(position, setting.Text.Evaluate(), position.Width, out height));
         panel.Controls.Add(CreateNumberSelect(position, (NumberSelect) setting));
         position.LinePosition += height + position.Margin;
       }
       else if (setting is Path)
       {
         int height;
         panel.Controls.Add(CreateLabel(position, setting.Text.Evaluate(), position.Width, out height));
         position.LinePosition += height + position.Margin;
         Panel browse = CreateBrowseEntry(position, (Path) setting);
         panel.Controls.Add(browse);
         position.LinePosition += browse.Height + position.Margin;
       }
       else if (setting is PreferenceList)
       {
         int height;
         panel.Controls.Add(CreateLabel(position, setting.Text.Evaluate(), position.Width, out height));
         position.LinePosition += height + position.Margin;
         Panel list = CreatePreferenceList(position, (PreferenceList) setting);
         panel.Controls.Add(list);
         position.LinePosition += list.Height + position.Margin;
       }
       else if (setting is SingleSelectionList)
       {
         int lblHeight;
         panel.Controls.Add(CreateLabel(position, setting.Text.Evaluate(), position.WidthColumnOne,
                                        out lblHeight));
         lblHeight += position.Margin;
         if (((SingleSelectionList) setting).Items.Count > 3) // ComboBox
         {
           ComboBox cmb = CreateComboBox(position);
           foreach (IResourceString item in ((SingleSelectionList)setting).Items)
             cmb.Items.Add(item.Evaluate());
           cmb.SelectedIndex = ((SingleSelectionList) setting).Selected;
           cmb.Tag = setting;
           SetHelp(cmb, setting.Help.Evaluate());
           cmb.Enabled = !setting.Disabled;
           panel.Controls.Add(cmb);
           if (lblHeight > position.LineHeight)
             position.LinePosition += (position.ItemHeight*(lblHeight/(position.ItemHeight*2)));
           position.LinePosition += position.LineHeight;
         }
         else // 3 or less items:            Radiobuttons
         {
           Panel radioPanel = CreateRadioPanel(position, (SingleSelectionList) setting);
           panel.Enabled = !setting.Disabled;
           panel.Controls.Add(radioPanel);
           position.LinePosition += radioPanel.Height + position.Margin;
         }
       }
       else if (setting is YesNo)
       {
         int lblHeight;
         panel.Controls.Add(CreateLabel(position, setting.Text.Evaluate(), position.WidthColumnOne, out lblHeight));
         lblHeight += position.Margin;
         CheckBox chk = CreateCheckBox(position);
         chk.Checked = ((YesNo) setting).Yes;
         chk.Tag = setting;
         SetHelp(chk, setting.Help.Evaluate());
         chk.Enabled = !setting.Disabled;
         panel.Controls.Add(chk);
         if (lblHeight > position.LineHeight)
           position.LinePosition += (position.ItemHeight*(lblHeight/(position.ItemHeight*2)));
         position.LinePosition += position.LineHeight;
       }
     }
   }
   panel.Height = position.LinePosition;
   return panel;
 }
示例#4
0
        /// <summary>
        /// Builds the specified node to a Panel.
        /// </summary>
        /// <param name="node">Node to build to the Panel.</param>
        /// <param name="position">Defines the positioning parameters.</param>
        /// <returns></returns>
        private Panel BuildToPanel(IConfigurationNode node, Position position)
        {
            Panel panel = new Panel();

            panel.Tag      = node == null ? null : node.ConfigObj;
            panel.AutoSize = false;
            panel.Height   = 0;
            panel.Width    = position.FullWidth;
            panel.Padding  = new Padding(0, 0, 0, 0);
            panel.Margin   = new Padding(0, 0, 0, 0);
            if (node == null || node.ConfigObj == null)
            {
                return(panel); // Return empty panel
            }
            panel.Name = string.Format("{0}_{1}", node.Location, node.ConfigObj);
            // Add heading
            if (node.ConfigObj is ConfigGroup)
            {
                panel.Controls.Add(CreateHeading(position, node.ConfigObj.Text.Evaluate()));
                position.LinePosition += position.LineHeight;
            }
            // Add subcontrols
            foreach (IConfigurationNode subNode in node.ChildNodes)
            {
                if (subNode.ConfigObj.Hidden)
                {
                    continue;
                }
                if (subNode.ConfigObj is ConfigGroup)
                {
                    Position pos = (Position)position.Clone();
                    pos.StartColumnOne += pos.Indent; // indent the first column
                    pos.WidthColumnOne -= pos.Indent; // shorten the width, so it doesn't overlap with column two
                    pos.LinePosition    = 0;          // reset linePosition, this is relative to the new control
                    // Make a recursive call to process the group to a Panel
                    Panel subPanel = BuildToPanel(subNode, pos);
                    subPanel.Anchor   = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
                    subPanel.Location = new Point(0, position.LinePosition);
                    subPanel.Enabled  = !subNode.ConfigObj.Disabled;
                    panel.Controls.Add(subPanel);
                    position.LinePosition += pos.LinePosition;
                }
                else if (subNode.ConfigObj is ConfigSetting)
                {
                    ConfigSetting setting = (ConfigSetting)subNode.ConfigObj;
                    setting.OnChangeEvent += _configChangedHandler;
                    if (setting is Entry)
                    {
                        panel.Controls.Add(CreateLabel(position, setting.Text.Evaluate()));
                        TextBox txt = CreateTextBox(position, setting.Columns);
                        txt.Text = ((Entry)setting).Value;
                        txt.Tag  = setting;
                        SetHelp(txt, setting.Help.Evaluate());
                        txt.Enabled = !setting.Disabled;
                        panel.Controls.Add(txt);
                        position.LinePosition += position.LineHeight + position.Margin;
                    }
                    else if (setting is LimitedNumberSelect)
                    {
                        int height;
                        panel.Controls.Add(CreateLabel(position, setting.Text.Evaluate(), position.Width, out height));
                        panel.Controls.Add(CreateLimitedNumberSelect(position, (LimitedNumberSelect)setting));
                        position.LinePosition += height + position.Margin;
                    }
                    else if (setting is MultipleEntryList)
                    {
                        panel.Controls.Add(CreateLabel(position, setting.Text.Evaluate()));
                        position.LinePosition += position.LineHeight;
                        TextBox txt = CreateMultiLineTextBox(position, setting.Rows);
                        txt.Tag = setting;
                        MultipleEntryList entryList = (MultipleEntryList)setting;
                        txt.Lines = new string[entryList.Lines.Count];
                        for (int i = 0; i < txt.Lines.Length; i++)
                        {
                            txt.Lines[i] = entryList.Lines[i];
                        }
                        SetHelp(txt, setting.Help.Evaluate());
                        txt.Enabled = !setting.Disabled;
                        panel.Controls.Add(txt);
                        position.LinePosition += txt.Height + position.Margin;
                    }
                    else if (setting is MultipleSelectionList)
                    {
                        int lblHeight;
                        panel.Controls.Add(CreateLabel(position, setting.Text.Evaluate(), position.WidthColumnOne,
                                                       out lblHeight));
                        position.LinePosition += lblHeight + position.Margin;
                        CheckedListBox        chk  = CreateCheckedListBox(position);
                        MultipleSelectionList list = ((MultipleSelectionList)setting);
                        for (int i = 0; i < list.Items.Count; i++)
                        {
                            chk.Items.Add(list.Items[i], list.SelectedIndices.Contains(i));
                        }
                        chk.Enabled = !setting.Disabled;
                        panel.Controls.Add(chk);
                        position.LinePosition += chk.Height + position.Margin;
                    }
                    else if (setting is NumberSelect)
                    {
                        int height;
                        panel.Controls.Add(CreateLabel(position, setting.Text.Evaluate(), position.Width, out height));
                        panel.Controls.Add(CreateNumberSelect(position, (NumberSelect)setting));
                        position.LinePosition += height + position.Margin;
                    }
                    else if (setting is Path)
                    {
                        int height;
                        panel.Controls.Add(CreateLabel(position, setting.Text.Evaluate(), position.Width, out height));
                        position.LinePosition += height + position.Margin;
                        Panel browse = CreateBrowseEntry(position, (Path)setting);
                        panel.Controls.Add(browse);
                        position.LinePosition += browse.Height + position.Margin;
                    }
                    else if (setting is PreferenceList)
                    {
                        int height;
                        panel.Controls.Add(CreateLabel(position, setting.Text.Evaluate(), position.Width, out height));
                        position.LinePosition += height + position.Margin;
                        Panel list = CreatePreferenceList(position, (PreferenceList)setting);
                        panel.Controls.Add(list);
                        position.LinePosition += list.Height + position.Margin;
                    }
                    else if (setting is SingleSelectionList)
                    {
                        int lblHeight;
                        panel.Controls.Add(CreateLabel(position, setting.Text.Evaluate(), position.WidthColumnOne,
                                                       out lblHeight));
                        lblHeight += position.Margin;
                        if (((SingleSelectionList)setting).Items.Count > 3) // ComboBox
                        {
                            ComboBox cmb = CreateComboBox(position);
                            foreach (IResourceString item in ((SingleSelectionList)setting).Items)
                            {
                                cmb.Items.Add(item.Evaluate());
                            }
                            cmb.SelectedIndex = ((SingleSelectionList)setting).Selected;
                            cmb.Tag           = setting;
                            SetHelp(cmb, setting.Help.Evaluate());
                            cmb.Enabled = !setting.Disabled;
                            panel.Controls.Add(cmb);
                            if (lblHeight > position.LineHeight)
                            {
                                position.LinePosition += (position.ItemHeight * (lblHeight / (position.ItemHeight * 2)));
                            }
                            position.LinePosition += position.LineHeight;
                        }
                        else // 3 or less items:            Radiobuttons
                        {
                            Panel radioPanel = CreateRadioPanel(position, (SingleSelectionList)setting);
                            panel.Enabled = !setting.Disabled;
                            panel.Controls.Add(radioPanel);
                            position.LinePosition += radioPanel.Height + position.Margin;
                        }
                    }
                    else if (setting is YesNo)
                    {
                        int lblHeight;
                        panel.Controls.Add(CreateLabel(position, setting.Text.Evaluate(), position.WidthColumnOne, out lblHeight));
                        lblHeight += position.Margin;
                        CheckBox chk = CreateCheckBox(position);
                        chk.Checked = ((YesNo)setting).Yes;
                        chk.Tag     = setting;
                        SetHelp(chk, setting.Help.Evaluate());
                        chk.Enabled = !setting.Disabled;
                        panel.Controls.Add(chk);
                        if (lblHeight > position.LineHeight)
                        {
                            position.LinePosition += (position.ItemHeight * (lblHeight / (position.ItemHeight * 2)));
                        }
                        position.LinePosition += position.LineHeight;
                    }
                }
            }
            panel.Height = position.LinePosition;
            return(panel);
        }