private void UpdateCommandLineSwitch(object sender)
        {
            LabeledTextBox    textBox = sender as LabeledTextBox;
            CommandLineSwitch arg     = textBox.Tag as CommandLineSwitch;

            arg.Enabled = textBox.Checked;
            arg.Value   = arg.Enabled ? textBox.Text : string.Empty;
        }
        private void ArgTextBox_TextChanged(object sender, EventArgs e)
        {
            LabeledTextBox textBox = sender as LabeledTextBox;

            if (textBox == null)
            {
                return;
            }
            if (textBox.Tag.GetType() == typeof(CommandLineArgument))
            {
                CommandLineArgument arg = textBox.Tag as CommandLineArgument;
                arg.Value = textBox.Text;
            }
            else if (textBox.Tag.GetType() == typeof(CommandLineSwitch))
            {
                UpdateCommandLineSwitch(textBox);
            }
            UpdateCommandLine();
        }
        private void CommandLineBuilderDialog_Shown(object sender, EventArgs e)
        {
            optionsPanel.Controls.Clear();

            int maxLabelWidth = 0;

            foreach (CommandLineArgument a in Helper.GetArguments())
            {
                LabeledTextBox argTextBox = new LabeledTextBox();
                argTextBox.Text         = a.Value;
                argTextBox.LabelText    = a.Name;
                argTextBox.Tag          = a;
                argTextBox.TextChanged += ArgTextBox_TextChanged;
                argTextBox.Hint         = a.Description;
                optionsPanel.Controls.Add(argTextBox);
                argTextBox.Width = optionsPanel.Width - 20 - argTextBox.Margin.Left;
                maxLabelWidth    = Math.Max(maxLabelWidth, argTextBox.LabelWidth);
            }

            foreach (Control c in optionsPanel.Controls)
            {
                LabeledTextBox t = c as LabeledTextBox;
                if (t == null)
                {
                    continue;
                }
                t.LabelAutoSize = false;
                t.LabelWidth    = maxLabelWidth;
            }

            maxLabelWidth = 0;
            foreach (KeyValuePair <string, CommandLineSwitch> sw in Helper.GetSwitches())
            {
                if (!string.IsNullOrEmpty(sw.Value.VariableName))
                {
                    LabeledTextBox argTextBox = new LabeledTextBox();
                    argTextBox.ShowCheckBox    = true;
                    argTextBox.Checked         = sw.Value.Enabled;
                    argTextBox.Text            = sw.Value.Value;
                    argTextBox.LabelText       = sw.Key;
                    argTextBox.Tag             = sw.Value;
                    argTextBox.TextChanged    += ArgTextBox_TextChanged;
                    argTextBox.CheckedChanged += ArgTextBox_CheckedChanged;
                    argTextBox.Hint            = sw.Value.Description;
                    argTextBox.Margin          = new Padding(0)
                    {
                        Left = 15, Top = 3, Bottom = 3
                    };
                    argTextBox.LabelAutoSize = true;
                    optionsPanel.Controls.Add(argTextBox);
                    argTextBox.Width = optionsPanel.Width - 20 - argTextBox.Margin.Left;
                    maxLabelWidth    = Math.Max(maxLabelWidth, argTextBox.LabelWidth);
                }
                else
                {
                    CheckBox chkBox = new CheckBox();
                    chkBox.Text            = sw.Key + "  (" + sw.Value.Description + ")";
                    chkBox.AutoSize        = true;
                    chkBox.Checked         = sw.Value.Enabled;
                    chkBox.Tag             = sw.Value;
                    chkBox.CheckedChanged += ChkBox_CheckedChanged;
                    chkBox.Margin          = new Padding(0)
                    {
                        Left = 15, Top = 3, Bottom = 3
                    };
                    chkBox.Width = optionsPanel.Width - 20 - chkBox.Margin.Left;
                    optionsPanel.Controls.Add(chkBox);
                }
            }

            foreach (Control c in optionsPanel.Controls)
            {
                LabeledTextBox t = c as LabeledTextBox;
                if (t == null)
                {
                    continue;
                }
                if (t.Tag.GetType() == typeof(CommandLineSwitch))
                {
                    t.LabelAutoSize = false;
                    t.LabelWidth    = maxLabelWidth;
                }
            }
            UpdateCommandLine();
        }