From what I understood, you want the text of a textbox to show the result of GenerateRandomCode
and show that value in a MessageBox
, too. You can do that like so:
int length = 10;
string msg;
private void button1_Click(object sender, EventArgs e)
{
msg = GenerateRandomCode(length);
textBox1.Text = msg;
MessageBox.Show(msg);
}
Random random = new Random();
public string GenerateRandomCode(int length)
{
string charPool = "ABCDEFGOPQRSTUVWXY1234567890ZabcdefghijklmHIJKLMNnopqrstuvwxyz";
StringBuilder rs = new StringBuilder();
/*Random random = new Random();*/
for (int i = 0; i < length; i++)
{
rs.Append(charPool[(int)(random.NextDouble() * charPool.Length)]);
}
return rs.ToString();
}