循环文本框
我有一个winforms应用程序,在屏幕上有37个文本框。每一个都按顺序编号:
DateTextBox0DateTextBox1 ...DateTextBox37
我试图遍历文本框并为每个文本框分配一个值:
int month = MonthYearPicker.Value.Month;int year = MonthYearPicker.Value.Year;int numberOfDays = DateTime.DaysInMonth(year, month);m_MonthStartDate = new DateTime(year, month, 1);m_MonthEndDate = new DateTime(year, month, numberOfDays);DayOfWeek monthStartDayOfWeek = m_MonthStartDate.DayOfWeek;int daysOffset = Math.Abs(DayOfWeek.Sunday - monthStartDayOfWeek);for (int i = 0; i <= (numberOfDays - 1); i++){ //Here is where I want to loop through the textboxes and assign values based on the 'i' value DateTextBox(daysOffset + i) = m_MonthStartDate.AddDays(i).Day.ToString();}
让我澄清一下,这些文本框出现在单独的面板上(其中37个)。因此,为了让我循环使用foreach,我必须遍历主控件(面板),然后遍历面板上的控件。它开始变得复杂。
有关如何将此值分配给文本框的任何建议?
慕桂英3389331
蝴蝶不菲