private static Control GetControlFromXmlElement(XElement element) { Control control = null; switch (element.Name.LocalName.ToLower()) { case "button": control = new Button(); break; case "checkbox": control = new CheckBox(); break; case "colorbar": control = new ColorBar(); break; case "colorpicker": control = new GuiControls.ColorPicker(); break; case "combobox": control = new ComboBox(); break; case "form": control = new Form(); break; case "groupbox": control = new GroupBox(); break; case "label": control = new Label(); break; case "linklabel": control = new LinkLabel(); break; case "listbox": control = new ListBox(); break; case "panel": control = new Panel(); break; case "picturebox": control = new PictureBox(); break; case "progressbar": control = new ProgressBar(); break; case "radiobutton": control = new RadioButton(); break; case "tabcontrol": control = new TabControl(); break; case "tabpage": control = new TabPage(); break; case "textbox": control = new TextBox(); break; case "timer": control = new Timer(); break; case "trackbar": control = new TrackBar(); break; case "hotkeycontrol": control = new HotkeyControl(); break; default: throw new Exception(element.Name.LocalName.ToLower()); } return(control); }
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); } }