private static string[] LabelsFromBox(CheckedListControl box)
        {
            List <string> result = new List <string>();

            foreach (string x in box.CheckedItems)
            {
                LabelModification sl = LabelModification.GetLabelByName(x);
                if (sl == null)
                {
                    throw new Exception("Label " + x + " does not exist.");
                }
                result.Add(sl.Name);
            }
            return(result.ToArray());
        }
        private void LabelsListBoxItemCheck(object sender, ItemCheckEventArgs e)
        {
            CheckedListControl box = (CheckedListControl)sender;

            if (e.NewValue != CheckState.Checked)
            {
                return;
            }
            if (deselectionMap.ContainsKey(e.Index))
            {
                foreach (int i in deselectionMap[e.Index])
                {
                    box.SetItemChecked(i, false);
                }
            }
        }
        /// <summary>
        /// Initializes an Ms1LabelPanel instance. Called only by constructor.
        /// Sets textLabels and labelsListBoxes.
        /// </summary>
        private void InitializeComponent1()
        {
            labelsListBoxes = new CheckedListControl[n];
            textLabels      = new Label[n];
            for (int i = 0; i < n; i++)
            {
                labelsListBoxes[i] = new CheckedListControl();
                labelsListBoxes[i].AddRange(labels);
                textLabels[i] = new Label {
                    Text = GetLabelText(i, n)
                };
            }
            // grid1 has one row to show "Light labels", "Medium labels", etc., and one row for the boxes
            // to select the relevant labels. It has one column for each label state.
            TableLayoutPanel grid1 = new TableLayoutPanel();

            grid1.RowStyles.Add(new RowStyle(SizeType.Absolute, 24));
            grid1.RowStyles.Add(new RowStyle(SizeType.Absolute, 126));
            for (int i = 0; i < n; i++)
            {
                grid1.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, 150));
            }
            for (int i = 0; i < n; i++)
            {
                grid1.Controls.Add(textLabels[i], i, 0);
                grid1.Controls.Add(labelsListBoxes[i], i, 1);
            }
            grid1.AutoScroll             = true;
            grid1.VerticalScroll.Enabled = false;
            grid1.Dock   = DockStyle.Top;
            grid1.Width  = 540;
            grid1.Height = 300;
            Controls.Add(grid1);
            Name   = "Ms1LabelPanel";
            Width  = 540;
            Height = 150;
            ResumeLayout(true);
        }