private void AddBooleanEntry(TweakOption option, Control panel)
        {
            var checkBox = new CheckBox()
            {
                Text     = option.Name,
                AutoSize = true,
                Padding  = new Padding(4, 0, 0, 0)
            };

            try
            {
                checkBox.Checked = option.GetValue <bool>();
                checkBox.Enabled = option.CanWrite;
            }
            catch
            {
                checkBox.Enabled    = false;
                checkBox.CheckState = CheckState.Indeterminate;
            }

            checkBox.CheckedChanged += (s, e2) =>
            {
                option.SetValue(checkBox.Checked);
                this.CheckRefresh(option);
            };

            panel.Controls.Add(checkBox);
        }
        private void AddColorEntry(TweakOption option, Control panel)
        {
            var colorButton = new ColorField()
            {
                Text     = option.Name,
                AutoSize = true
            };

            try
            {
                colorButton.Color = option.GetValue <Color>();
            }
            catch
            {
                colorButton.Color   = Color.Transparent;
                colorButton.Enabled = false;
            }

            colorButton.ColorChanged += (s, e2) =>
            {
                option.SetValue(colorButton.Color);
                this.CheckRefresh(option);
            };

            panel.Controls.Add(colorButton);
        }
        private void AddStringEntry(TweakOption option, Control panel)
        {
            var parent = new LabeledControl()
            {
                Text     = option.Name,
                AutoSize = true
            };

            var textBox = new TextBox();

            try
            {
                textBox.Text    = option.GetValue <string>();
                textBox.Enabled = option.CanWrite;
            }
            catch
            {
                textBox.Enabled = false;
            }

            textBox.TextChanged += (s, e2) =>
            {
                option.SetValue(textBox.Text);
                this.CheckRefresh(option);
            };

            parent.Child = textBox;

            panel.Controls.Add(parent);
        }
        private void AddEnumEntry(TweakOption option, Control panel)
        {
            var parent = new LabeledControl()
            {
                Text     = option.Name,
                AutoSize = true
            };

            var comboBox = new ComboBox()
            {
                DropDownStyle = ComboBoxStyle.DropDownList,
                DrawMode      = DrawMode.OwnerDrawVariable
            };

            comboBox.DrawItem += (s, e2) =>
            {
                //Can't render empty items.
                if (e2.Index < 0)
                {
                    return;
                }

                e2.DrawBackground();

                //Use display name as label, if not available use property name as fallback.
                var    item             = (Enum)comboBox.Items[e2.Index];
                string valueDisplayName = item.GetAttribute <DisplayNameAttribute>()?.DisplayName ?? item.ToString();

                e2.Graphics.DrawString(valueDisplayName, comboBox.Font, new SolidBrush(e2.ForeColor), e2.Bounds.X, e2.Bounds.Y);
            };

            try
            {
                foreach (Enum value in Enum.GetValues(option.Type))
                {
                    comboBox.Items.Add(value);
                }

                comboBox.SelectedItem = option.GetValue <object>();

                comboBox.Enabled = option.CanWrite;
            }
            catch
            {
                comboBox.Enabled = false;
            }

            comboBox.SelectedValueChanged += (s, e2) =>
            {
                option.SetValue(comboBox.SelectedItem);
                this.CheckRefresh(option);
            };

            parent.Child = comboBox;

            panel.Controls.Add(parent);
        }
        private void AddIntegerEntry(TweakOption option, Control panel)
        {
            var parent = new LabeledControl()
            {
                Text     = option.Name,
                AutoSize = true
            };

            var rangeAttribute = option.GetAttribute <RangeAttribute>();

            int?mininum = null;
            int?maximum = null;

            if (rangeAttribute != null)
            {
                mininum = (int)rangeAttribute.Mininum;
                maximum = (int)rangeAttribute.Maximum;
            }

            if (Properties.Settings.Default.PreferSliders && mininum != null && maximum != null)
            {
                var slider = new TrackBar()
                {
                    Minimum       = mininum ?? int.MinValue,
                    Maximum       = maximum ?? int.MaxValue,
                    TickFrequency = int.MaxValue,
                    AutoSize      = false,
                    Height        = 24
                };

                try
                {
                    slider.Value   = option.GetValue <int>();
                    slider.Enabled = option.CanWrite;
                }
                catch
                {
                    slider.Enabled = false;
                }

                slider.ValueChanged += (s, e2) =>
                {
                    option.SetValue(slider.Value);
                    this.CheckRefresh(option);
                };

                parent.Child = slider;
            }
            else
            {
                var upDown = new NumericUpDown()
                {
                    Minimum = mininum ?? int.MinValue,
                    Maximum = maximum ?? int.MaxValue
                };

                try
                {
                    upDown.Value   = option.GetValue <int>();
                    upDown.Enabled = option.CanWrite;
                }
                catch
                {
                    upDown.Enabled = false;
                }

                upDown.ValueChanged += (s, e2) =>
                {
                    option.SetValue((int)upDown.Value);
                    this.CheckRefresh(option);
                };

                parent.Child = upDown;
            }

            panel.Controls.Add(parent);
        }