示例#1
0
        public StyleManagerForm()
        {
            InitializeComponent();

            suppressUpdate = false;

            //initialize controls
            controlList = new Dictionary <GuiControls.ControlType, GuiControls.Control>();

            string preview = "Preview";

            previewForm = new GuiControls.Form(new Point(1, 1))
            {
                Size = new Size(424, 200),
                Text = preview
            };

            previewControl = previewForm;

            var button = new GuiControls.Button {
                Text = preview
            };

            controlList.Add(GuiControls.ControlType.Button, button);

            var checkbox = new GuiControls.CheckBox {
                Text = preview
            };

            controlList.Add(GuiControls.ControlType.CheckBox, checkbox);

            var comboBox = new GuiControls.ComboBox
            {
                Items = new[] { preview },
                Text  = preview
            };

            controlList.Add(GuiControls.ControlType.ComboBox, comboBox);

            controlList.Add(GuiControls.ControlType.Form, previewForm);

            var groupbox = new GuiControls.GroupBox
            {
                Text = preview,
                Size = new Size(100, 100)
            };

            controlList.Add(GuiControls.ControlType.GroupBox, groupbox);

            var hotkeyControl = new GuiControls.HotkeyControl {
                Hotkey = Keys.Control | Keys.A
            };

            controlList.Add(GuiControls.ControlType.HotkeyControl, hotkeyControl);

            var label = new GuiControls.Label {
                Text = preview
            };

            controlList.Add(GuiControls.ControlType.Label, label);

            var linklabel = new GuiControls.LinkLabel {
                Text = preview
            };

            controlList.Add(GuiControls.ControlType.LinkLabel, linklabel);

            var listbox = new GuiControls.ListBox {
                Items = new[] { preview }
            };

            controlList.Add(GuiControls.ControlType.ListBox, listbox);

            var picturebox = new GuiControls.PictureBox {
                Size = new Size(100, 100)
            };

            controlList.Add(GuiControls.ControlType.PictureBox, picturebox);

            var panel = new GuiControls.Panel {
                Size = new Size(100, 100)
            };

            controlList.Add(GuiControls.ControlType.Panel, panel);

            var progressbar = new GuiControls.ProgressBar {
                Value = 50
            };

            controlList.Add(GuiControls.ControlType.ProgressBar, progressbar);

            var radiobutton = new GuiControls.RadioButton {
                Text = preview
            };

            controlList.Add(GuiControls.ControlType.RadioButton, radiobutton);

            var tabControl = new GuiControls.TabControl {
                Size = new Size(100, 100)
            };

            controlList.Add(GuiControls.ControlType.TabControl, tabControl);

            var tabPage = new GuiControls.TabPage {
                Text = preview
            };

            tabControl.AddTabPage(tabPage);
            controlList.Add(GuiControls.ControlType.TabPage, tabPage);

            var textbox = new GuiControls.TextBox {
                Text = preview
            };

            controlList.Add(GuiControls.ControlType.TextBox, textbox);

            var trackbar = new GuiControls.TrackBar();

            controlList.Add(GuiControls.ControlType.TrackBar, trackbar);

            foreach (var kv in controlList)
            {
                if (!(kv.Key == GuiControls.ControlType.Form || kv.Key == GuiControls.ControlType.TabPage))
                {
                    kv.Value.DesignerHidden = true;
                    previewForm.AddControl(kv.Value);
                }

                controlsListBox.Items.Add(kv.Key);
            }
        }
示例#2
0
        private void canvasPictureBox_DragDrop(object sender, DragEventArgs e)
        {
            if (e.Data.GetDataPresent(typeof(ControlType)))
            {
                var type = (ControlType)e.Data.GetData(typeof(ControlType));

                var cm = ControlManager.Instance();
                GuiControls.Control newControl = null;
                switch (type)
                {
                case ControlType.Button:
                    var button = new GuiControls.Button();
                    button.Text = button.Name = button.DefaultName + cm.GetControlCountPlusOne(typeof(GuiControls.Button));
                    newControl  = button;
                    break;

                case ControlType.CheckBox:
                    var checkBox = new GuiControls.CheckBox();
                    checkBox.Text = checkBox.Name = checkBox.DefaultName + cm.GetControlCountPlusOne(typeof(GuiControls.CheckBox));
                    newControl    = checkBox;
                    break;

                case ControlType.ColorBar:
                    var colorBar = new ColorBar();
                    colorBar.Name = colorBar.DefaultName + cm.GetControlCountPlusOne(typeof(ColorBar));
                    newControl    = colorBar;
                    break;

                case ControlType.ColorPicker:
                    var colorPicker = new GuiControls.ColorPicker();
                    colorPicker.Name = colorPicker.DefaultName + cm.GetControlCountPlusOne(typeof(GuiControls.ColorPicker));
                    newControl       = colorPicker;
                    break;

                case ControlType.ComboBox:
                    var comboBox = new GuiControls.ComboBox();
                    comboBox.Text = comboBox.Name = comboBox.DefaultName + cm.GetControlCountPlusOne(typeof(GuiControls.ComboBox));
                    newControl    = comboBox;
                    break;

                case ControlType.GroupBox:
                    var groupBox = new GuiControls.GroupBox();
                    groupBox.Text = groupBox.Name = groupBox.DefaultName + cm.GetControlCountPlusOne(typeof(GuiControls.GroupBox));
                    newControl    = groupBox;
                    break;

                case ControlType.Label:
                    var label = new GuiControls.Label();
                    label.Text = label.Name = label.DefaultName + cm.GetControlCountPlusOne(typeof(GuiControls.Label));
                    newControl = label;
                    break;

                case ControlType.LinkLabel:
                    var linkLabel = new GuiControls.LinkLabel();
                    linkLabel.Text = linkLabel.Name = linkLabel.DefaultName + cm.GetControlCountPlusOne(typeof(GuiControls.LinkLabel));
                    newControl     = linkLabel;
                    break;

                case ControlType.ListBox:
                    var listBox = new GuiControls.ListBox();
                    listBox.Name = listBox.DefaultName + cm.GetControlCountPlusOne(typeof(GuiControls.ListBox));
                    newControl   = listBox;
                    break;

                case ControlType.Panel:
                    var panel = new GuiControls.Panel();
                    panel.Name = panel.DefaultName + cm.GetControlCountPlusOne(typeof(GuiControls.Panel));
                    newControl = panel;
                    break;

                case ControlType.PictureBox:
                    var pictureBox = new GuiControls.PictureBox();
                    pictureBox.Name = pictureBox.DefaultName + cm.GetControlCountPlusOne(typeof(GuiControls.PictureBox));
                    newControl      = pictureBox;
                    break;

                case ControlType.ProgressBar:
                    var progressBar = new GuiControls.ProgressBar();
                    progressBar.Name = progressBar.DefaultName + cm.GetControlCountPlusOne(typeof(GuiControls.ProgressBar));
                    newControl       = progressBar;
                    break;

                case ControlType.RadioButton:
                    var radioButton = new GuiControls.RadioButton();
                    radioButton.Text = radioButton.Name = radioButton.DefaultName + cm.GetControlCountPlusOne(typeof(GuiControls.RadioButton));
                    newControl       = radioButton;
                    break;

                case ControlType.TabControl:
                    var tabControl = new GuiControls.TabControl();
                    tabControl.Name = tabControl.DefaultName + cm.GetControlCountPlusOne(typeof(GuiControls.TabControl));
                    var tempTabPage = new GuiControls.TabPage();
                    tempTabPage.Text = tempTabPage.Name = tempTabPage.DefaultName + cm.GetControlCountPlusOne(typeof(GuiControls.TabPage));
                    tabControl.AddTabPage(tempTabPage);
                    AddControlToList(tempTabPage);
                    newControl = tabControl;
                    break;

                case ControlType.TabPage:
                    var tabPage = new GuiControls.TabPage();
                    tabPage.Text = tabPage.Name = tabPage.DefaultName + cm.GetControlCountPlusOne(typeof(GuiControls.TabPage));
                    newControl   = tabPage;
                    break;

                case ControlType.TextBox:
                    var textBox = new GuiControls.TextBox();
                    textBox.Name = textBox.Text = textBox.DefaultName + cm.GetControlCountPlusOne(typeof(GuiControls.TextBox));
                    newControl   = textBox;
                    break;

                case ControlType.Timer:
                    var timer = new GuiControls.Timer();
                    timer.Name = timer.DefaultName + cm.GetControlCountPlusOne(typeof(GuiControls.Timer));
                    newControl = timer;
                    break;

                case ControlType.TrackBar:
                    var trackBar = new GuiControls.TrackBar();
                    trackBar.Name = trackBar.DefaultName + cm.GetControlCountPlusOne(typeof(GuiControls.TrackBar));
                    newControl    = trackBar;
                    break;

                case ControlType.HotkeyControl:
                    var hotkeyControl = new HotkeyControl();
                    hotkeyControl.Name = hotkeyControl.DefaultName + cm.GetControlCountPlusOne(typeof(HotkeyControl));
                    newControl         = hotkeyControl;
                    break;
                }
                if (newControl == null)
                {
                    return;
                }

                RegisterEvents(newControl);

                AddControlToList(newControl);

                var location = canvasPictureBox.PointToClient(new Point(e.X, e.Y));
                var parent   = FindContainerControlUnderMouse(location);
                newControl.Location = location.Substract(parent.ContainerAbsoluteLocation);
                parent.AddControl(newControl);
            }
        }