如何为每个生成的路线随机化r.Stroke.Color
的颜色?
var myFile = new CsvFile(@".\netting.csv");
for (int row = 1; row < myFile.Rows.Count; row++)
{
for (int col = 0; col < myFile.Rows[row].Fields.Count; col++)
{
var markersOverlay = new GMapOverlay("markers");
var startMarker = new GMarkerGoogle(new PointLatLng(Convert.ToDouble(myFile.Rows[row].Fields[3]), Convert.ToDouble(myFile.Rows[row].Fields[4])), GMarkerGoogleType.green_dot);
var goalMarker = new GMarkerGoogle(new PointLatLng(Convert.ToDouble(myFile.Rows[row].Fields[5]), Convert.ToDouble(myFile.Rows[row].Fields[6])), GMarkerGoogleType.red_dot);
markersOverlay.Markers.Add(startMarker);
markersOverlay.Markers.Add(goalMarker);
gMapControl1.Overlays.Add(markersOverlay);
var start = new PointLatLng(Convert.ToDouble(myFile.Rows[row].Fields[3]), Convert.ToDouble(myFile.Rows[row].Fields[4]));
var end = new PointLatLng(Convert.ToDouble(myFile.Rows[row].Fields[5]), Convert.ToDouble(myFile.Rows[row].Fields[6]));
var route = GoogleMapProvider.Instance.GetRoute(start, end, false, false, 15);
var r = new GMapRoute(route.Points, "My route");
r.Stroke.Width = 2;
r.Stroke.Color = Color.SeaGreen;
var routesOverlay = new GMapOverlay("routes");
routesOverlay.Routes.Add(r);
gMapControl1.Overlays.Add(routesOverlay);
}
}
答案 0 :(得分:1)
你可以使用像
这样的随机颜色方法Color randomColor(){
System.Random rdm = new Random();
int red = rdm.Next(0,255);
int green = rdm.Next(0,255);
int blue = rdm.Next(0,255);
return Color.FromArgb(red,green,blue);
}
然后你可以将这种颜色分配给你的路线:
route.Stroke = new Pen(randomColor(),3);