public void UpdateSplits()
        {
            if (isLoading)
            {
                return;
            }

            Splits.Clear();
            foreach (Control c in flowMain.Controls)
            {
                if (c is SplitterSplitSettings)
                {
                    SplitterSplitSettings setting = (SplitterSplitSettings)c;
                    if (!string.IsNullOrEmpty(setting.cboType.Text))
                    {
                        uint offset = 0;
                        try {
                            offset = Convert.ToUInt32(setting.txtOffset.Text, 16);
                        } catch { }
                        long value;
                        long.TryParse(setting.txtValue.Text, out value);
                        Splits.Add(new SplitInfo()
                        {
                            Type        = SplitterSplitSettings.GetEnumValue <SplitType>(setting.cboType.Text),
                            Size        = SplitterSplitSettings.GetEnumValue <ValueSize>(setting.cboSize.Text),
                            Offset      = offset,
                            Value       = value,
                            ShouldSplit = setting.chkSplit.Checked
                        });
                    }
                }
            }
        }
        public void LoadSettings()
        {
            isLoading = true;
            this.flowMain.SuspendLayout();

            for (int i = flowMain.Controls.Count - 1; i > 0; i--)
            {
                flowMain.Controls.RemoveAt(i);
            }

            foreach (SplitInfo split in Splits)
            {
                SplitterSplitSettings setting = new SplitterSplitSettings();
                setting.cboType.DataSource = GetAvailableDescriptions <SplitType>();
                setting.cboType.Text       = SplitterSplitSettings.GetEnumDescription <SplitType>(split.Type);
                setting.cboSize.DataSource = GetAvailableDescriptions <ValueSize>();
                setting.cboSize.Text       = SplitterSplitSettings.GetEnumDescription <ValueSize>(split.Size);
                setting.txtOffset.Text     = split.Offset.ToString("X");
                setting.txtValue.Text      = split.Value.ToString();
                setting.chkSplit.Checked   = split.ShouldSplit;
                AddHandlers(setting);

                flowMain.Controls.Add(setting);
            }

            isLoading = false;
            this.flowMain.ResumeLayout(true);
        }
 private void RemoveHandlers(SplitterSplitSettings setting)
 {
     setting.cboType.SelectedIndexChanged -= ControlChanged;
     setting.cboSize.SelectedIndexChanged -= ControlChanged;
     setting.txtOffset.TextChanged        -= ControlChanged;
     setting.txtValue.TextChanged         -= ControlChanged;
     setting.chkSplit.CheckedChanged      -= ControlChanged;
     setting.btnRemove.Click -= btnRemove_Click;
 }
 private void AddHandlers(SplitterSplitSettings setting)
 {
     setting.cboType.SelectedIndexChanged += new EventHandler(ControlChanged);
     setting.cboSize.SelectedIndexChanged += new EventHandler(ControlChanged);
     setting.txtOffset.TextChanged        += new EventHandler(ControlChanged);
     setting.txtValue.TextChanged         += new EventHandler(ControlChanged);
     setting.chkSplit.CheckedChanged      += new EventHandler(ControlChanged);
     setting.btnRemove.Click += new EventHandler(btnRemove_Click);
 }
        private void btnAddSplit_Click(object sender, EventArgs e)
        {
            SplitterSplitSettings setting = new SplitterSplitSettings();
            List <string>         names   = GetAvailableDescriptions <SplitType>();

            setting.cboType.DataSource = names;
            setting.cboType.Text       = names[0];
            names = GetAvailableDescriptions <ValueSize>();
            setting.cboSize.DataSource = names;
            setting.cboSize.Text       = names[0];
            AddHandlers(setting);

            flowMain.Controls.Add(setting);
            UpdateSplits();
        }
        private void flowMain_DragOver(object sender, DragEventArgs e)
        {
            SplitterSplitSettings data        = (SplitterSplitSettings)e.Data.GetData(typeof(SplitterSplitSettings));
            FlowLayoutPanel       destination = (FlowLayoutPanel)sender;
            Point p     = destination.PointToClient(new Point(e.X, e.Y));
            var   item  = destination.GetChildAtPoint(p);
            int   index = destination.Controls.GetChildIndex(item, false);

            if (index == 0)
            {
                e.Effect = DragDropEffects.None;
            }
            else
            {
                e.Effect = DragDropEffects.Move;
                int oldIndex = destination.Controls.GetChildIndex(data);
                if (oldIndex != index)
                {
                    destination.Controls.SetChildIndex(data, index);
                    destination.Invalidate();
                }
            }
        }