private void button5_Click(object sender, EventArgs e) { try { size = Convert.ToInt32(textBox1.Text); if (size > 1 && size < 26) { Form2 newf = new Form2(size + 1); newf.Owner = this; tb = newf.creat_table(); newf.ShowDialog(); if (Table) { Bitmap btm = new Bitmap(pictureBox1.Width, pictureBox1.Height); Graphics.FromImage(btm).Clear(Color.White); array_of_arc.Clear(); array_of_peak.Clear(); pictureBox1.Image = btm; draw(); pictureBox1.Invalidate(); for (int i = 0; i < size; i++) { Peak point = new Peak(); point.peak(array_of_peak.Count, 0, 0, 0); array_of_peak.Add(point); } for (int i = 1; i <= size; i++) { for (int j = 1; j <= size; j++) { Arc line = new Arc(); try { Single a; List <int> index = new List <int>(2); bool weight = Single.TryParse(tb[i, j].Text, System.Globalization.NumberStyles.Number, System.Globalization.NumberFormatInfo.CurrentInfo, out a); if (a <= int.MaxValue) { index.Add(i - 1); index.Add(j - 1); line.Box(array_of_peak, index, (int)a, false); array_of_arc.Add(line); } else { MessageBox.Show("Ваша дуга не может быть такой тяжелой!", "FATAL ERROR!", MessageBoxButtons.OK, MessageBoxIcon.Error); array_of_arc.Clear(); array_of_peak.Clear(); Table = false; return; } } catch { } } } } } else { MessageBox.Show("Введите целое положительное число больше 1 и меньше 26!", "FATAL ERROR!", MessageBoxButtons.OK, MessageBoxIcon.Error); } } catch { MessageBox.Show("Введите целое положительное число больше 1 и меньше 26!", "FATAL ERROR!", MessageBoxButtons.OK, MessageBoxIcon.Error); } } // задать матрицу достижимости и взять из нее данные
} // проверка ввода в textbox private void pictureBox1_MouseDown(object sender, MouseEventArgs e) // клик по picturebox { if (Draw == true) { Bitmap btm = new Bitmap(pictureBox1.Width, pictureBox1.Height); Peak point = new Peak(); int X = e.X - 13; int Y = e.Y - 13; if (point.match(array_of_peak, X, Y) >= 0) { return; } point.peak(array_of_peak.Count, X, Y, i); array_of_peak.Add(point); pictureBox1.Image = btm; draw(); pictureBox1.Invalidate(); if (i == 6) { i = -1; } i++; } // задаем точки if (Clear == true) { Bitmap btm = new Bitmap(pictureBox1.Width, pictureBox1.Height); Peak point = new Peak(); Arc line = new Arc(); int X = e.X - 13; int Y = e.Y - 13; int index = point.match(array_of_peak, X, Y); // мы кликнули по точке? int index_road_del = line.match(array_of_arc, X, Y); // мы кликнули по прямой? int loop = line.search_for_loop(array_of_arc, X, Y); // мы кликнули по петле? int arc = line.search_for_arc(array_of_arc, X, Y); if (index >= 0) { for (int j = 0; j < array_of_arc.Count; j++) { if (array_of_arc[j].peak1.number_peak == array_of_peak[index].number_peak || array_of_arc[j].peak2.number_peak == array_of_peak[index].number_peak) { array_of_arc.RemoveAt(j); j--; } } array_of_peak.RemoveAt(index); pictureBox1.Image = btm; draw(); pictureBox1.Invalidate(); return; } if (arc >= 0) { array_of_arc.RemoveAt(arc); pictureBox1.Image = btm; draw(); pictureBox1.Invalidate(); return; } if (loop >= 0) { array_of_arc.RemoveAt(loop); pictureBox1.Image = btm; draw(); pictureBox1.Invalidate(); return; } if (index_road_del >= 0) { array_of_arc.RemoveAt(index_road_del); pictureBox1.Image = btm; draw(); pictureBox1.Invalidate(); return; } } // удаляем if (Line == true) { Bitmap btm = new Bitmap(pictureBox1.Width, pictureBox1.Height); Peak point = new Peak(); Arc line = new Arc(); int X = e.X - 13; int Y = e.Y - 13; int index = point.match(array_of_peak, X, Y); if (index >= 0) { road.Add(index); } if (road.Count == 2) { bool arc = false; if (!line.search_for_matches(array_of_arc, array_of_peak, road, ref arc)) { line.Box(array_of_peak, road, 0, arc); array_of_arc.Add(line); pictureBox1.Image = btm; draw(); pictureBox1.Invalidate(); } road.Clear(); } } // задаеем дуги if (Weight == true) { Bitmap btm = new Bitmap(pictureBox1.Width, pictureBox1.Height); Peak point = new Peak(); Arc line = new Arc(); int X = e.X - 13; int Y = e.Y - 13; int index_road_del = line.match(array_of_arc, X, Y); int loop = line.search_for_loop(array_of_arc, X, Y); int arc = line.search_for_arc(array_of_arc, X, Y); if (arc >= 0) { CreatWeight newForm = new CreatWeight(); newForm.Owner = this; newForm.ShowDialog(); array_of_arc[arc].weight = ix; pictureBox1.Image = btm; draw(); pictureBox1.Invalidate(); return; } if (loop >= 0) // клик по петле { CreatWeight newForm = new CreatWeight(); newForm.Owner = this; newForm.ShowDialog(); array_of_arc[loop].weight = ix; pictureBox1.Image = btm; draw(); pictureBox1.Invalidate(); return; } if (index_road_del >= 0) // клик по дуге { CreatWeight newForm = new CreatWeight(); newForm.Owner = this; newForm.ShowDialog(); array_of_arc[index_road_del].weight = ix; pictureBox1.Image = btm; draw(); pictureBox1.Invalidate(); return; } ix = 0; } // задаем вес }