示例#1
0
        /// <summary>
        /// Adds a new <see cref="Rule"/> to the table (including checkboxes).
        /// </summary>
        /// <param name="rule"><see cref="Rule"/></param>
        private void AddRule(Rule rule)
        {
            int     rowCount  = tableLayoutPanel.RowCount++;
            Padding margin    = new Padding(1, 0, 0, 1);
            Label   ruleLabel = new Label
            {
                AutoSize  = false,
                Width     = 500,
                Height    = 50,
                Text      = rule.Name,
                BackColor = Color.White,
                TextAlign = ContentAlignment.MiddleLeft,
                Margin    = margin
            };

            for (int col = 1; col < tableLayoutPanel.ColumnCount; col++)
            {
                CheckBox checkBox = new CheckBox
                {
                    AutoSize   = false,
                    Height     = 50,
                    Width      = 50,
                    BackColor  = Color.White,
                    CheckAlign = ContentAlignment.MiddleCenter,
                    Margin     = margin
                };
                Fund columnFund = tableLayoutPanel.GetControlFromPosition(col, 0).DataBindings[0].DataSource as Fund;
                if (rule.FundList.Contains(columnFund))
                {
                    checkBox.Checked = true;
                }
                tableLayoutPanel.Controls.Add(checkBox);
            }

            FormUtility.BindObjectToControl(ruleLabel, rule);
            FormUtility.AddControlWithContextMenu(tableLayoutPanel, contextMenu, ruleLabel, 0, rowCount);
        }