I’m quite sure I’m missing some sort of really obvious solution to this. It might be my state of rank newbie, but I am completely lost at this point.
Essentially, I need to create a WinForm that will allow the user to input text in textBox1 and textBox2. Then, at the click of button1, the text in textBox2 replaces that in textBox1. From what I can tell, this needs to go into the button1_Click event.
Here’s a few examples of what I’ve tried so far:
private void button1_Click(object sender, EventArgs e)
{
string output;
output = textBox2.Text;
textBox1.Text = output;
}
And the simplest solution I could find:
private void button1_Click(object sender, EventArgs e)
{
textBox1.Text = textBox2.Text;
}
As well as:
this.textBox1.Text = this.textBox2.Text;
None of these work. I can enter the text just fine in either textbox, but nothing happens when I actually click the button. My mother would turn me over her knee if she could hear my response to that lack of… well, response.
Like I said, I’m sure I’m missing something really obvious. But I’ve now consulted my textbook, Google, Bing and at least a half-dozen forums with no luck in finding anything that has let me solve this on my own. Could someone be kind enough to tell me what it is I’m doing wrong?
It sounds like your event handler is not wired in.
Go to your form designer and click on Button1, then look at the Click event and see if it says
button1_Click. (The list of events is in the Properties window. Click the yellow lightning bold icon to view the events).Alternatively, if you want to just check that the event handler is wired up properly you can open (assuming your form is called MyForm) MyForm.Designer.cs and look for this line:
or something real close to that.