I am new to Visual C# and I am trying to sort a RichTextBox and generate non repeating numbers. Please help. (I am using Visual C# 2010)
My code is as follows...
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace RandomNumber
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
Random rnd = new Random();
private void button1_Click(object sender, EventArgs e)
{
numericUpDown1.Enabled = false;
numericUpDown2.Enabled = false;
numericUpDown3.Enabled = false;
richTextBox1.Clear();
button1.Enabled = false;
int a = Convert.ToInt32(numericUpDown1.Value);
int b = Convert.ToInt32(numericUpDown2.Value);
int c = Convert.ToInt32(numericUpDown3.Value);
for (int counter = 1; counter <= c; counter++)
{
int num = rnd.Next((b - 1), (a + 1))+1;//This lets us get the maximun and minimun in the generated sequence
if (num < 0)
{
num = num * -1;
//Sets negative numbers to that of a positive.
}
richTextBox1.Text = num + ", " + richTextBox1.Text;
if(counter==c)
{
button1.Enabled = true;
numericUpDown1.Enabled = true;//Sets numericbox maximum to Enabled state
numericUpDown2.Enabled = true;//Sets numericbox minimum to Enabled state
numericUpDown3.Enabled = true;//Sets numericbox for maximun generated numbers to an enabled state
//MessageBox.Show("Number of generated numbers is:"+c," Completed");
}
}
}
private void timer1_Tick(object sender, EventArgs e)
{
if (numericUpDown2.Value >= numericUpDown1.Value)
{
numericUpDown1.Value = numericUpDown2.Value + 1;
//This makes it so that the minimun is never greater than the maximun
}
}
private void button2_Click(object sender, EventArgs e)
{
this.Close();
}
}
}