private void saveToolStripMenuItem_Click(object sender, EventArgs e) { var sfd = new SaveFileDialog { DefaultExt = "xml" }; sfd.Filter = "OSHGui File (*." + sfd.DefaultExt + ")|*." + sfd.DefaultExt; sfd.FileName = form.Name + "." + sfd.DefaultExt; if (sfd.ShowDialog() == DialogResult.OK) { ControlSerializer.Serialize(form).Save(sfd.FileName); } }
private void canvasPictureBox_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e) { if (GuiControls.Control.FocusedControl != null) { if (e.KeyCode == Keys.Delete) { var removeControl = GuiControls.Control.FocusedControl; var parent = removeControl.RealParent ?? form; RecursiveRemove(removeControl); parent.Focus(); controlComboBox.SelectedIndex = 0; } else if (e.Control && e.KeyCode == Keys.C) { if (GuiControls.Control.FocusedControl == form) { return; } var copiedControl = GuiControls.Control.FocusedControl.Copy(); Clipboard.SetData( "OSHVisualGuiControl", ControlSerializer.Serialize(copiedControl).ToString() ); } else if (e.Control && e.KeyCode == Keys.X) { if (GuiControls.Control.FocusedControl == form) { return; } Clipboard.SetData( "OSHVisualGuiControl", ControlSerializer.Serialize(GuiControls.Control.FocusedControl).ToString() ); RecursiveRemove(GuiControls.Control.FocusedControl); controlComboBox.SelectedIndex = 0; } else if (e.Control && e.KeyCode == Keys.V) { if (!Clipboard.ContainsData("OSHVisualGuiControl")) { return; } if (Clipboard.GetData("OSHVisualGuiControl") is string serializedControl) { var copiedControl = ControlSerializer.Deserialize(XElement.Parse(serializedControl)); if (copiedControl != null) { ContainerControl parent = null; if (copiedControl is GuiControls.TabPage && !(GuiControls.Control.FocusedControl is GuiControls.TabControl)) { MessageBox.Show("A TabPage needs to be inserted into a TabControl."); return; } if (GuiControls.Control.FocusedControl is ContainerControl) { parent = GuiControls.Control.FocusedControl as ContainerControl; } else { parent = GuiControls.Control.FocusedControl.RealParent; } //check if name already exists if (ControlManager.Instance().FindByName(copiedControl.Name, null) != null) { //then change the name copiedControl.Name = copiedControl.DefaultName + ControlManager.Instance().GetControlCountPlusOne(copiedControl.GetType()); //and change the location copiedControl.Location = copiedControl.Location.Add(new Point(10, 10)); } parent.AddControl(copiedControl); AddControlToList(copiedControl); if (copiedControl is ContainerControl) { foreach (var control in (copiedControl as ContainerControl).PreOrderVisit()) { if (control is ScalableControl) { RegisterEvents(control); AddControlToList(control); } } controlComboBox.SelectedItem = copiedControl; } RegisterEvents(copiedControl); } } } } }