Reputation: 65
namespace GenerateApp
{
public partial class Form1 : Form
{
string[] name = new string[4];
public Form1()
{
InitializeComponent();
name[0] = textBox2.Text;
name[1] = textBox3.Text;
name[2] = textBox5.Text;
name[3] = textBox6.Text;
}
private void button1_Click(object sender, EventArgs e)
{
for (int i = 0; i < name.Length; i++)
{
}
}
}
}
Ok first of all I must mention that i'm at the very beginning with programming and i'm trying to do something in my eyes quite simple but doesn't work and I need your help. I want every time that i click on a button, in my current textboxes to be generated another names. Example textbox2.Text to be textbox3.Text, textbox3.Text to be textbox5.Text and so on till it repeats. Can someone tell me a method of how to do it? I would gladly appreciate it
Upvotes: 2
Views: 82
Reputation: 6965
Seem like you just wanna move names between boxes. All you need is a variable to hold the first name.
private void button1_Click(object sender, EventArgs e)
{
var tmp = textBox1.Text;
textBox1.Text = textBox2.Text;
textBox2.Text = textBox3.Text;
textBox3.Text = textBox4.Text;
textBox4.Text = tmp;
}
Upvotes: 2