Wednesday, September 9, 2009

Generate Random Number2




namespace RandomNoGenerate2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

int min,max,val=0;
Random rdm;
bool b;
private void btn_RGenerate_Click(object sender, EventArgs e)
{
rdm = new Random();
min = Convert.ToInt32(txt_min.Text);
max = Convert.ToInt32(txt_max.Text);
val = rdm.Next(min, max);
textBox1.Text = val.ToString();
}

private void btn_Add_Click(object sender, EventArgs e)
{
b = false;
rdm = new Random();
min = Convert.ToInt32(txt_min.Text);
max = Convert.ToInt32(txt_max.Text);
val = rdm.Next(min, max);
textBox1.Text = val.ToString();

for (int i = 0; i < listBox1.Items.Count; i++)
{
if (val == Convert.ToInt32(listBox1.Items[i]))
b=true;
}
if(b)
textBox1.BackColor = Color.Red;
else
textBox1.BackColor = Color.White;

}
}
}

No comments:

Post a Comment

Followers