예제 #1
0
 private void RegisterEvents(GuiControls.Control scalableControl)
 {
     scalableControl.MouseDown += control_MouseDown;
     scalableControl.MouseMove += control_MouseMove;
     scalableControl.MouseUp   += control_MouseUp;
     (scalableControl as ScalableControl).DragEnd += control_DragEnd;
 }
예제 #2
0
        private void controlsListBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (previewControl != null)
            {
                if (!(previewControl is GuiControls.Form || previewControl is GuiControls.TabPage))
                {
                    previewControl.DesignerHidden = true;
                }
            }

            var type = (GuiControls.ControlType)controlsListBox.SelectedItem;

            previewControl = controlList[type];
            previewControl.DesignerHidden = false;

            controlStyle = style.ControlStyles[type];

            suppressUpdate = true;

            controlForeColorTextBox.Color     = controlStyle.ForeColor;
            controlBackColorTextBox.Color     = controlStyle.BackColor;
            controlUseDefaultCheckBox.Checked = controlStyle.UseDefault;

            suppressUpdate = false;

            UpdateControlStyle();
        }
예제 #3
0
 private void RecursiveRemove(GuiControls.Control control)
 {
     if (control is ContainerControl container)
     {
         foreach (var it in container.Controls.ToArray())                 //ToArray fixes invalid iterator error
         {
             RecursiveRemove(it);
         }
     }
     control.RealParent.RemoveControl(control);
     RemoveControlFromList(control);
 }
예제 #4
0
        private void RemoveControlFromList(GuiControls.Control control)
        {
            try
            {
                ControlManager.Instance().UnregisterControl(control);

                controlComboBox.Items.Remove(control);
                controlComboBox.SelectedIndex = 0;

                canvasPictureBox.Invalidate();
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }
        }
예제 #5
0
        private void AddControlToList(GuiControls.Control control)
        {
            try
            {
                control.Name = control.DefaultName + ControlManager.Instance().GetControlCountPlusOne(control.GetType());

                ControlManager.Instance().RegisterControl(control);

                controlComboBox.Items.Add(control);
                controlComboBox.SelectedItem = control;

                canvasPictureBox.Invalidate();
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }
        }
예제 #6
0
        private void control_MouseMove(GuiControls.Control sender, Mouse mouse)
        {
            if (controlShouldDrag)
            {
                var deltaLocation = mouse.Location.Substract(oldControlLocation);
                if (controlRealDrag || Math.Abs(deltaLocation.X) > 5 || Math.Abs(deltaLocation.Y) > 5)
                {
                    controlRealDrag    = true;
                    sender.Location    = sender.Location.Add(deltaLocation);
                    oldControlLocation = mouse.Location;
                }

                var container = FindContainerControlUnderMouse(mouse.Location);
                if (container != GuiControls.Control.FocusedControl.RealParent)
                {
                    container.IsHighlighted = true;
                }
            }
        }
예제 #7
0
        private void control_MouseUp(GuiControls.Control sender, Mouse mouse)
        {
            controlShouldDrag = false;
            controlRealDrag   = false;

            if (!(GuiControls.Control.FocusedControl is GuiControls.Form))
            {
                var container = FindContainerControlUnderMouse(mouse.Location);
                if (GuiControls.Control.FocusedControl.RealParent != container)
                {
                    GuiControls.Control.FocusedControl.Location = GuiControls.Control.FocusedControl.AbsoluteLocation.Substract(container.ContainerAbsoluteLocation);

                    var oldContainer = GuiControls.Control.FocusedControl.Parent as ContainerControl;
                    oldContainer.RemoveControl(GuiControls.Control.FocusedControl);
                    container.AddControl(GuiControls.Control.FocusedControl);
                }

                controlPropertyGrid.Refresh();
            }
        }
예제 #8
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);
            }
        }
예제 #9
0
 private void control_DragEnd(GuiControls.Control sender)
 {
     controlPropertyGrid.Refresh();
 }
예제 #10
0
 private void control_MouseDown(GuiControls.Control sender, Mouse mouse)
 {
     controlShouldDrag  = true;
     oldControlLocation = mouse.Location;
 }
예제 #11
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);
            }
        }