private void tsp_foundNewBestTour(object sender, TspEventArgs e) { if (this.InvokeRequired) { try { this.Invoke(new DrawEventHandler(DrawTour), new object[] { sender, e }); return; } catch (Exception hata) { MessageBox.Show(hata.Message);// exception döndürürse hatayı mesaj olarak aldırır. } } DrawTour(sender, e); }
public void DrawTour(object sender, TspEventArgs e) // tur çizim metodu { this.lblTur.Text = Math.Round(e.BestTour.Fitness, 2).ToString(CultureInfo.CurrentCulture); //tur sayısını yazdırır. this.lblTekrar.Text = e.Generation.ToString(CultureInfo.CurrentCulture); // tekrar sayısını yazdırır. if (cityImage == null) { cityImage = new Bitmap(picture.Width, picture.Height); } cityGraphics = Graphics.FromImage(cityImage); // resim alanı boş ise nokta, şehir belirlememizi sağlar. int lastCity = 0; int nextCity = e.BestTour[0].Connection1; Point ulCorner = new Point(0, 0); cityGraphics.FillRectangle(Brushes.White, 0, 0, picture.Width, picture.Height); cityGraphics.DrawImage(YcityImage, ulCorner); foreach (City city in e.CityList) { //şehirleri daire olarak çizdirmemizi sağlar. cityGraphics.FillEllipse(Brushes.DarkRed, city.Location.X - 2, city.Location.Y - 2, 8, 8); // çizilen şehirlerin bağlantısını sağlar. cityGraphics.DrawLine(Pens.DarkRed, cityList[lastCity].Location, cityList[nextCity].Location); if (lastCity != e.BestTour[nextCity].Connection1) { lastCity = nextCity; nextCity = e.BestTour[nextCity].Connection1; } else { lastCity = nextCity; nextCity = e.BestTour[nextCity].Connection2; } } this.picture.Image = cityImage; if (e.Complete) { Start.Text = "Başlat"; lblDurum.Text = "Şehir listesi açmak için tıklayın => Şehir Dosyası Aç "; lblDurum.ForeColor = Color.Black; } }