I have a form that has 90 buttons on it, one button for each day. When a user first signs into the program, they enter their user name and a date. I want to take the date the user entered and auto fill the text fields of each button. For example the text for btnDay1 would be 18 Mar, btnDay2 would be 19 Mar, etc., etc.
Someone suggested using this code:
DateTime time = dateTimepicker1.Value; //this is user selected date, you can use your own way
foreach(Button b in this.Controls.OfType<Button>())
{
if(b.Name != "button1" || b.Name != "button2")
{
b.Text = time.Date.ToString("dd MMM");
time = time.Date.AddDays(1); //setting for next button
}
}
but the compiler tells me that dateTimepicker1 doesn’t exist in its current content. I have never used dateTimepicker and it’s not in my textbook so I am unfamiliar with how to use it. I looked at the MSDN library but the example there is so completely different than DateTime time = dateTimepicker1.Value that all it does is leave me more confused than I was before.
if you have a textbox to get the inputs from the user then
It expects that you have two buttons button1 and button2 that need to be avoided.
To make interface better, you can put a date picker instead of the textbox and change its name to
dateTimepicker1and use your code in the question.