Creating a Windows Forms Application in C#, I have a program that I am trying to insert a date into a text box (textBox3), and I can’t get the date to show up. I created a button on the form that pops up, and the date shows up just fine. But, the text box never populates. Any suggestions? Here’s the code:
private void textBox3_TextChanged(object sender, EventArgs e)
{
var today = DateTime.Today.ToString("dd/MM/yyyy");
textBox3.Text = today;
}
private void button1_Click(object sender, EventArgs e)
{
var today = DateTime.Today.ToString("MM/dd/yyyy");
MessageBox.Show("Today is " + today + ".");
}
Your text field will only update when you start typing anything on the textbox because, apparently, you are hooking up to the Text_Changed event.
Type something in
textBox3and you’ll see that the text becomes whatevertodayis holding.