سلام
تا جایی که من متوجه شدم شما میخواهی لیبل ها را بصورت تصادفی انتخاب کنی. به نظر من باید برای هر لیبل یک شماره در نظر بگیری بعد باید 3 عدد تصادفی تولید کنی که رنج این عدد تصادفی بین 1 تا 10 هست. بعنوان مثال اگر عدد 1 تولید شد رنگ لیبل شماره 1 را تغییر بده و .... شما در کد زیر فقط باید بجای Label1 اسم لیبل را بنویسید و ....
using System;
using System.Collections.Generic;
public class Program
{
public static void Main()
{
//int[] a = {1,2,3,4,5,6,7,8,9,10,11,12};
IList<int> a = new List<int>();
a.Add(1);
a.Add(2);
a.Add(3);
a.Add(4);
a.Add(5);
a.Add(6);
a.Add(7);
a.Add(8);
a.Add(9);
a.Add(10);
Random c = new Random();
Random rnd = new Random();
int y;
for(int j = 1; j<=3; j++)
{
y = c.Next(0, a.Count-1);
Console.WriteLine(a[y]);
a.Remove(a[y]);
y = c.Next(0, a.Count-1);
Console.WriteLine(a[y]);
a.Remove(a[y]);
Console.WriteLine("///");
if (a[y]==1)
Label1.ForeColor = Color.FromArgb(rnd.Next(255), rnd.Next(255), rnd.Next(255));//(R, G, B) (0, 0, 0 = black)
if (a[y]==2)
Label2.ForeColor = Color.FromArgb(rnd.Next(255), rnd.Next(255), rnd.Next(255));//(R, G, B) (0, 0, 0 = black)
if (a[y]==1)
Label1.ForeColor = Color.FromArgb(rnd.Next(255), rnd.Next(255), rnd.Next(255));//(R, G, B) (0, 0, 0 = black)
if (a[y]==3)
Label3.ForeColor = Color.FromArgb(rnd.Next(255), rnd.Next(255), rnd.Next(255));//(R, G, B) (0, 0, 0 = black)
if (a[y]==4)
Label4.ForeColor = Color.FromArgb(rnd.Next(255), rnd.Next(255), rnd.Next(255));//(R, G, B) (0, 0, 0 = black)
if (a[y]==5)
Label5.ForeColor = Color.FromArgb(rnd.Next(255), rnd.Next(255), rnd.Next(255));//(R, G, B) (0, 0, 0 = black)
if (a[y]==6)
Label6.ForeColor = Color.FromArgb(rnd.Next(255), rnd.Next(255), rnd.Next(255));//(R, G, B) (0, 0, 0 = black)
if (a[y]==7)
Label7.ForeColor = Color.FromArgb(rnd.Next(255), rnd.Next(255), rnd.Next(255));//(R, G, B) (0, 0, 0 = black)
if (a[y]==8)
Label8.ForeColor = Color.FromArgb(rnd.Next(255), rnd.Next(255), rnd.Next(255));//(R, G, B) (0, 0, 0 = black)
if (a[y]==9)
Label9.ForeColor = Color.FromArgb(rnd.Next(255), rnd.Next(255), rnd.Next(255));//(R, G, B) (0, 0, 0 = black)
if (a[y]==10)
Label10.ForeColor = Color.FromArgb(rnd.Next(255), rnd.Next(255), rnd.Next(255));//(R, G, B) (0, 0, 0 = black)
}
}
}