public static void ShowHandles() { try { if (CurrentControl != null) { for (int i = 0; i < 8; i++) { Rectangle[i].Visible = true; } } string Tag = (string)CurrentControl.Tag; string YmlName = Tag.Substring(Tag.LastIndexOf(":") + 1) + ".xml"; if (Tag.StartsWith("image:")) { SGuiFrame.Im.XShow = ControlW.ToString(); SGuiFrame.Im.YShow = ControlH.ToString(); SGuiFrame.Im.X = (CurrentControl.Location.X - Main.Mainfrm.Gui_X).ToString(); SGuiFrame.Im.Y = (CurrentControl.Location.Y - Main.Mainfrm.Gui_Y).ToString(); XmlMethods.ModifyIm(Main.ImagesPath + YmlName); XmlMethods.ReadIm(Main.ImagesPath + YmlName); Main.Mainfrm.GuiPropertyGrid.SelectedObject = Im; } else if (Tag.StartsWith("button:")) { SGuiFrame.Bt.Width = ControlW.ToString(); SGuiFrame.Bt.High = ControlH.ToString(); SGuiFrame.Bt.X = (CurrentControl.Location.X - Main.Mainfrm.Gui_X).ToString(); SGuiFrame.Bt.Y = (CurrentControl.Location.Y - Main.Mainfrm.Gui_Y).ToString(); XmlMethods.ModifyBt(Main.ButtonsPath + YmlName); XmlMethods.ReadBt(Main.ButtonsPath + YmlName); Main.Mainfrm.GuiPropertyGrid.SelectedObject = Bt; } else if (Tag.StartsWith("text:")) { SGuiFrame.Txt.X = (CurrentControl.Location.X - Main.Mainfrm.Gui_X).ToString(); SGuiFrame.Txt.Y = (CurrentControl.Location.Y - Main.Mainfrm.Gui_Y).ToString(); XmlMethods.ModifyTxt(Main.TextsPath + YmlName); XmlMethods.ReadTxt(Main.TextsPath + YmlName); Main.Mainfrm.GuiPropertyGrid.SelectedObject = Txt; } } catch { //MessageBox.Show("66"); } }
public void GuiCodeTxt_TextChanged(object sender, EventArgs e) { try { LineP.Invalidate(); //比如 map_title ok string currentTabName = Main.Mainfrm.tabControl1.TabPages[Main.Mainfrm.tabControl1.SelectedIndex].Text.Substring(Main.Mainfrm.tabControl1.TabPages[Main.Mainfrm.tabControl1.SelectedIndex].Text.IndexOf(":") + 1); //map_title.yml [文档] string newName = currentTabName.Substring(0, currentTabName.LastIndexOf("[") - 5); if (Main.Mainfrm.tabControl1.TabPages[Main.Mainfrm.tabControl1.SelectedIndex].Tag == "image") { Stream stream = File.Open(Main.ImagesPath + newName + ".xml", FileMode.Open, FileAccess.Write, FileShare.ReadWrite); stream.Seek(0, SeekOrigin.Begin); stream.SetLength(0); stream.Close(); File.WriteAllText(Main.ImagesPath + newName + ".xml", Main.Mainfrm.tabControl1.TabPages[Main.Mainfrm.tabControl1.SelectedIndex].Controls[0].Controls[0].Text); XmlMethods.ReadIm(Main.ImagesPath + newName + ".xml"); Main.Mainfrm.GuiPropertyGrid.SelectedObject = SGuiFrame.Im; } else if (Main.Mainfrm.tabControl1.TabPages[Main.Mainfrm.tabControl1.SelectedIndex].Tag == "button") { Stream stream = File.Open(Main.ButtonsPath + newName + ".xml", FileMode.Open, FileAccess.Write, FileShare.ReadWrite); stream.Seek(0, SeekOrigin.Begin); stream.SetLength(0); stream.Close(); File.WriteAllText(Main.ButtonsPath + newName + ".xml", Main.Mainfrm.tabControl1.TabPages[Main.Mainfrm.tabControl1.SelectedIndex].Controls[0].Controls[0].Text); XmlMethods.ReadBt(Main.ButtonsPath + newName + ".xml"); Main.Mainfrm.GuiPropertyGrid.SelectedObject = SGuiFrame.Bt; } else if (Main.Mainfrm.tabControl1.TabPages[Main.Mainfrm.tabControl1.SelectedIndex].Tag == "text") { Stream stream = File.Open(Main.TextsPath + newName + ".xml", FileMode.Open, FileAccess.Write, FileShare.ReadWrite); stream.Seek(0, SeekOrigin.Begin); stream.SetLength(0); stream.Close(); File.WriteAllText(Main.TextsPath + newName + ".xml", Main.Mainfrm.tabControl1.TabPages[Main.Mainfrm.tabControl1.SelectedIndex].Controls[0].Controls[0].Text); XmlMethods.ReadTxt(Main.TextsPath + newName + ".xml"); Main.Mainfrm.GuiPropertyGrid.SelectedObject = SGuiFrame.Txt; } } catch { } }
public void SelectControl(object sender, EventArgs e) { try { if (CurrentControl is Control) { CurrentControl.Cursor = oldCursor; //Remove event any pre-existing event handlers appended by this class CurrentControl.MouseDown -= new MouseEventHandler(this.SGuiFrame_MouseDown); CurrentControl.MouseMove -= new MouseEventHandler(this.SGuiFrame_MouseMove); CurrentControl.MouseUp -= new MouseEventHandler(this.SGuiFrame_MouseUp); CurrentControl.DoubleClick -= new EventHandler(this.SGuiFrame_DoubleClick); CurrentControl.Resize -= new EventHandler(this.SGuiFrame_Resize); //CurrentControl.LostFocus -= new EventHandler(this.SGuiFrame_LostFocus); // CurrentControl = null; } CurrentControl = (Control)sender; //Add event handlers for moving the selected control around CurrentControl.MouseDown += new MouseEventHandler(this.SGuiFrame_MouseDown); CurrentControl.MouseMove += new MouseEventHandler(this.SGuiFrame_MouseMove); CurrentControl.MouseUp += new MouseEventHandler(this.SGuiFrame_MouseUp); CurrentControl.DoubleClick += new EventHandler(this.SGuiFrame_DoubleClick); CurrentControl.Resize += new EventHandler(this.SGuiFrame_Resize); //CurrentControl.LostFocus += new EventHandler(this.SGuiFrame_LostFocus); //Add sizing handles to Control's container (Form or PictureBox) for (int i = 0; i < 8; i++) { CurrentControl.Parent.Controls.Add(Rectangle[i]); Rectangle[i].BringToFront(); } string Tag = (string)CurrentControl.Tag; string YmlName = Tag.Substring(Tag.LastIndexOf(":") + 1); if (Tag.StartsWith("image:")) { //先改变GuiComboBox的值非常重要,如果等到propertygrid控件选择完对象以后再改变变量值会发生改变,触发guicomboBox IndexChanged的modify就会错误保存。 Main.Mainfrm.GuiComboBox.SelectedIndex = Main.Mainfrm.GuiComboBox.Items.IndexOf("图像:" + YmlName + ".yml"); XmlMethods.ReadIm(Main.ImagesPath + YmlName + ".xml"); ControlW = Convert.ToInt32(SGuiFrame.Im.XShow); ControlH = Convert.ToInt32(SGuiFrame.Im.YShow); Main.Mainfrm.GuiPropertyGrid.SelectedObject = Im; } else if (Tag.StartsWith("button:")) { Main.Mainfrm.GuiComboBox.SelectedIndex = Main.Mainfrm.GuiComboBox.Items.IndexOf("按钮:" + YmlName + ".yml"); XmlMethods.ReadBt(Main.ButtonsPath + YmlName + ".xml"); ControlW = Convert.ToInt32(SGuiFrame.Bt.Width); ControlH = Convert.ToInt32(SGuiFrame.Bt.High); Main.Mainfrm.GuiPropertyGrid.SelectedObject = Bt; } else if (Tag.StartsWith("text:")) { Main.Mainfrm.GuiComboBox.SelectedIndex = Main.Mainfrm.GuiComboBox.Items.IndexOf("文本:" + YmlName + ".yml"); XmlMethods.ReadTxt(Main.TextsPath + YmlName + ".xml"); Main.Mainfrm.GuiPropertyGrid.SelectedObject = Txt; } //Position sizing handles around Control MoveHandles(); //Display sizing handles ShowHandles(); oldCursor = CurrentControl.Cursor; CurrentControl.Cursor = Cursors.SizeAll; //CurrentControl.BringToFront(); } catch (Exception ex) { MessageBox.Show("请检查xml文本编辑框内容,缺少了尖括号和标签等请手动填补上去"); } }