private void button1_Click(object sender, EventArgs e) { if (Paint_Status == 2 || Paint_Status == 4) { if (Edge_Cursor > 0) { // remove a point Edge_Cursor -= 1; if (Circle_Cursor < 0) { Circle_Cursor = 0; } CellW.Invalidate(); } else { // remove a circle Circle_Cursor -= 1; if (Circle_Cursor < 0) { Circle_Cursor = 0; } CellW.Invalidate(); } } if (Paint_Status == 3) { // restore last circle if (Radius[Circle_Cursor] > 0.01) { Circle_Cursor++; } CellW.Invalidate(); } }
private void button5_Click(object sender, EventArgs e) { int i = 0; string FileCDir = FileDir + "//" + FileName + ".txt"; // no more files string FileCDir1 = FileDir + "//" + FileName + "(" + Convert.ToString(i) + ").txt"; if (if_open) { while (System.IO.File.Exists(FileCDir1)) { FileCDir1 = FileDir + "//" + FileName + "(" + Convert.ToString(++i) + ").txt"; } if (i > 0) { FileCDir1 = FileDir + "//" + FileName + "(" + Convert.ToString(--i) + ").txt"; } else if (System.IO.File.Exists(FileCDir)) { FileCDir1 = FileCDir; } if (System.IO.File.Exists(FileCDir1)) { FileStream fs = new FileStream(FileCDir1, FileMode.Open); StreamReader sw = new StreamReader(fs); Circle_Cursor = Convert.ToInt32(sw.ReadLine()); for (i = 0; i < Circle_Cursor; i++) { string[] p = new string[4]; p = sw.ReadLine().Split(','); Center[i, 0] = Convert.ToInt32(p[1]); Center[i, 1] = Convert.ToInt32(p[2]); Radius[i] = Convert.ToDouble(p[3]); } Paint_Status = 4; CellW.Invalidate(); sw.Close(); fs.Close(); } } }
private void button7_Click(object sender, EventArgs e) { Edge_Cursor = 0; CellW.Invalidate(); Paint_Status = 5; }
private void CellW_MouseDown(object sender, MouseEventArgs e) { if (Paint_Status == 2) { if (e.Button == MouseButtons.Left && e.Clicks == 1) { // 左键单击 if (Edge_Cursor >= 10) { //大于10个点 Paint_Status = 20; CellW.Invalidate(); } else { //Edge[Edge_Cursor, 0] = Cell.PointToClient(Control.MousePosition).X; //Edge[Edge_Cursor, 1] = Cell.PointToClient(Control.MousePosition).Y; //修正十字坐标中心位置 Edge[Edge_Cursor, 0] = Cell.PointToClient(Control.MousePosition).X - 2; Edge[Edge_Cursor, 1] = Cell.PointToClient(Control.MousePosition).Y - 2; Edge_Cursor += 1; CellW.Invalidate(); } } else if (e.Button == MouseButtons.Right && e.Clicks == 1 && Edge_Cursor > 2) { // 右键单击 Paint_Status = 20; CellW.Invalidate(); } } else if (Paint_Status == 3) { if (e.Button == MouseButtons.Left && e.Clicks == 1) { // 左键单击 if (Circle_Cursor > 0) { int X = Cell.PointToClient(Control.MousePosition).X - 2; int Y = Cell.PointToClient(Control.MousePosition).Y - 2; int MatchIndex = 0; double MatchPercent = 0; for (int i = 0; i < Circle_Cursor; i++) { double mp = Math.Sqrt((X - Center[i, 0]) * (X - Center[i, 0]) + (Y - Center[i, 1]) * (Y - Center[i, 1])); if (mp <= Radius[i]) { mp = 1 - mp / Radius[i]; } else { mp = 0.0; } if (MatchPercent < mp) { MatchPercent = mp; MatchIndex = i; } } if (MatchPercent >= 0.01) { if (MatchIndex == Circle_Cursor - 1) { Circle_Cursor--; } else { int[] CMI = { Center[MatchIndex, 0], Center[MatchIndex, 1] }; double RMI = Radius[MatchIndex]; Center[MatchIndex, 0] = Center[Circle_Cursor - 1, 0]; Center[MatchIndex, 1] = Center[Circle_Cursor - 1, 1]; Radius[MatchIndex] = Radius[Circle_Cursor - 1]; Center[Circle_Cursor - 1, 0] = CMI[0]; Center[Circle_Cursor - 1, 1] = CMI[1]; Radius[--Circle_Cursor] = RMI; } } CellW.Invalidate(); } } } }