Friday, October 29, 2010

C# Tutorial: Simple Password Generator [Add Text to Clipboard]

Here is the code

using System.IO;

Random rnd = new Random(); int[] symb = { 33, 35, 36, 37, 38, 42, 95 }; int length; 
private void button2_Click(object sender, EventArgs e)
{
    StringWriter sw = new StringWriter(); length = Convert.ToInt32(textBox1.Text);
    for (; length > 0; length--)
    {
        switch (rnd.Next(1, 5))
        {
            case 1: sw.Write((char)rnd.Next(65, 91)); break;
            case 2: sw.Write((char)rnd.Next(97, 123)); break;
            case 3: sw.Write((char)rnd.Next(48, 58)); break;
            case 4: sw.Write((char)symb[rnd.Next(0, 7)]); break;  
        }
    }
    textBox2.Text = sw.ToString(); 
}

private void button1_Click(object sender, EventArgs e)
{
    Clipboard.SetText(textBox2.Text);   
}

Or download the solution

6 comments:

  1. Awesome, that's just what I was hunting for! Your article just saved me alot of looking around

    I'll make certain to put this in good use!

    ReplyDelete
  2. O my god you are so awesome ! :)
    Your video amazing.

    I know what i'm saying cuz i know ;)
    Some people like to talk before video i but do not like they talk a lot and do nothing.

    But you can make it awesomely with out talk and fast.
    Thank you ;)

    ReplyDelete
  3. can you make a video how to create rich text editor with hyperlink dialog box or something more ?
    Thank you.

    ReplyDelete
  4. please how can i display text on left side? only text

    ReplyDelete