Beispiel #1
0
        private FlowLayoutPanel CreateOption(string text = "", string tag = "")
        {
            var option = new FlowLayoutPanel
            {
                Width  = optionsLayoutPanel.Width - optionWidthOffset,
                Height = optionHeight
            };

            var optionButton = new Button
            {
                Text  = string.IsNullOrEmpty(tag) ? createShortcutButtonText : tag,
                Width = createShortcutButtonWidth
            };

            option.Controls.Add(optionButton);

            var optionTextBox = new TextBox
            {
                Text  = text,
                Width = optionsLayoutPanel.Width - textBoxWidthOffset,
                Tag   = tag
            };

            option.Controls.Add(optionTextBox);

            var editOptionButton = new Button
            {
                Text  = editOptionButtonText,
                Width = editOptionButtonWidth
            };

            option.Controls.Add(editOptionButton);

            var menu = new ContextMenuStrip();
            var changeHotkeyMenuItem = menu.Items.Add("Change Shortcut");
            var deleteOptionMenuItem = menu.Items.Add("Delete");

            changeHotkeyMenuItem.Click += (o, e) => {
                var  setShortcutForm = new SetShortcut();
                Keys shortcut        = 0;
                setShortcutForm.FormClosing += (oo, ee) => shortcut = setShortcutForm.Shortcut;
                var result = setShortcutForm.ShowDialog();
                if (result == DialogResult.OK)
                {
                    if (!string.IsNullOrEmpty(tag))
                    {
                        optionShortcuts.Remove((Keys)Enum.Parse(typeof(Keys), tag, true));
                    }
                    tag = shortcut.ToString();

                    if (shortcut == 0)
                    {
                        optionButton.Text = string.Empty;
                        optionTextBox.Tag = string.Empty;
                    }
                    else
                    {
                        optionButton.Text = shortcut.ToString();
                        optionTextBox.Tag = shortcut.ToString();
                        optionShortcuts.Add(shortcut, optionButton);
                    }
                    SaveOptions();
                }
            };
            deleteOptionMenuItem.Click += (o, e) => {
                optionsLayoutPanel.Controls.Remove(option);
                SaveOptions();
            };

            optionButton.Click += (o, e) =>
            {
                if (fileOperations[selectedCopyTypeIndex](fileNameTextBox.Text, optionTextBox.Text))
                {
                    Close();
                }
            };
            optionTextBox.TextChanged += (o, e) => SaveOptions();
            editOptionButton.Click    += (o, e) =>
                                         menu.Show(option.PointToScreen(new Point(editOptionButton.Location.X, editOptionButton.Location.Y + editOptionButton.Height)));
            if (!string.IsNullOrEmpty(tag))
            {
                optionShortcuts.Add((Keys)Enum.Parse(typeof(Keys), tag, true), optionButton);
            }

            return(option);
        }