private void pictureBox1_MouseUp(object sender, MouseEventArgs e) { if (this.RecordMacro == true) { int x = e.X; int y = e.Y; int top = (this.pictureBox1.Height - Convert.ToInt32(this.txtY.Text)) / 2; int left = (this.pictureBox1.Width - Convert.ToInt32(this.txtX.Text)) / 2; x = x - left; y = y - top; if (x > 0 && y > 0 && x < Convert.ToInt32(this.txtX.Text) && y < Convert.ToInt32(this.txtY.Text)) { MouseDownBegin = DateTime.Now; MouseDownEnd = DateTime.Now; string oldMacro = this.txtMacro.Text; string newMacro = ""; newMacro = newMacro + " MouseUp :" + x.ToString() + " , " + y.ToString() + System.Environment.NewLine; this.txtMacro.Text = oldMacro + newMacro; this.MouseX = e.X; this.MouseY = e.Y; GRBLcommand comm = new GRBLcommand(); comm.Name = "MouseUp"; comm.Type = 9; comm.X = x; comm.Y = y; this.ExecutiveComm(comm); } } }
private GRBLcommand GetGRBLcommand(string comm) { // MouseDown: 117 , 250 // MouseUp: 117 , 250 // MouseMove: 123 GRBLcommand a = new GRBLcommand(); a.Type = 9; string[] m = comm.Split(':'); if (m.Length > 0) { a.Name = m[0].Trim(); if (a.Name == "Delayed") { a.X = Convert.ToInt16(m[1]); } else { string[] n = m[1].Split(','); a.X = Convert.ToInt16(n[0]); a.Y = Convert.ToInt16(n[1]); } } return(a); }
private void ExecutiveComm(GRBLcommand comm) { if (comm.Name == "Delayed") { this.GoPoint(10, comm.X, 0); //this.Stop(comm.X * 1000); } else if (comm.Name == "MouseDown") { if (this.commOldName != "MouseDown") { TestPen("UP"); } this.GoPoint(9, comm.X, comm.Y); this.commOldName = "MouseDown"; } else if (comm.Name == "PenDown") { if (this.commOldName != "PenDown") { TestPen("DOWN"); } this.commOldName = "PenDown"; } else if (comm.Name == "MouseUp") { if (this.commOldName != "MouseUp") { TestPen("UP"); } this.GoPoint(9, comm.X, comm.Y); this.commOldName = "MouseUp"; } else if (comm.Name == "PenUp") { if (this.commOldName != "PenUp") { TestPen("UP"); } this.commOldName = "PenUp"; } else if (comm.Name == "MouseMove") { if (this.commOldName != "MouseMove") { TestPen("DOWN"); } this.GoPoint(9, comm.X, comm.Y); this.commOldName = "MouseMove"; } }
private void ExecutiveMacro(string Macro) { this.GoBasePoint(); string[] MacroList = Macro.Split(Environment.NewLine.ToCharArray()); for (int i = 0; i < MacroList.Length; i++) { string commandTxT = MacroList[i].Trim(); if (commandTxT != "") { GRBLcommand comm = GetGRBLcommand(commandTxT); ExecutiveComm(comm); } } this.GoBasePoint(); }
private void pictureBox1_MouseMove(object sender, MouseEventArgs e) { if (this.RecordMacro == true) { if (e.Button == MouseButtons.Left) { int x = e.X; int y = e.Y; int top = (this.pictureBox1.Height - Convert.ToInt32(this.txtY.Text)) / 2; int left = (this.pictureBox1.Width - Convert.ToInt32(this.txtX.Text)) / 2; x = x - left; y = y - top; if (x > 0 && y > 0 && x < Convert.ToInt32(this.txtX.Text) && y < Convert.ToInt32(this.txtY.Text)) { string oldMacro = this.txtMacro.Text; string newMacro = ""; MouseDownEnd = DateTime.Now; TimeSpan ts = MouseDownEnd.Subtract(MouseDownBegin).Duration(); this.toolStripStatusLabel3.Text = ts.Seconds.ToString(); if (ts.Seconds > 0) { newMacro = newMacro + " Delayed :" + ts.Seconds.ToString() + System.Environment.NewLine; } newMacro = newMacro + "MouseMove :" + x.ToString() + " , " + y.ToString() + System.Environment.NewLine; if (Math.Abs(this.MouseX - e.X) > 5 || Math.Abs(this.MouseY - e.Y) > 5) { MouseDownBegin = DateTime.Now; MouseDownEnd = DateTime.Now; this.txtMacro.Text = oldMacro + newMacro; this.MouseX = e.X; this.MouseY = e.Y; GRBLcommand comm = new GRBLcommand(); comm.Name = "MouseMove"; comm.Type = 9; comm.X = x; comm.Y = y; this.ExecutiveComm(comm); } } } } }