private void WriteDates()
{
//the day value is used to write the dates on the calendar, the init value is used to tell us where
//to start in the calendar
int day = 1;
int init = GetDayNumber(1);
for (int i = init; i <= 6; i++)
{
//writes out the dates in the first row starting from the correct position
tableLayoutPanel1.GetControlFromPosition(i, 1).Text = day.ToString(System.Threading.Thread.CurrentThread.CurrentUICulture);
day += 1;
}
int daysInMonth;
try
{
daysInMonth = UmAlQuraInstance.GetDaysInMonth(m_selectedYear, m_selectedMonth);
}
catch (ArgumentException exception)
{
MessageBox.Show(exception.Message);
return;
}
for (int i = 2; i <= 5; i++)
{
for (int j = 0; j <= 6; j++)
{
//writes out the remaining dates in the calendar watching out for the number of day in the month*/
if (day <= daysInMonth)
{
tableLayoutPanel1.GetControlFromPosition(j, i).Text = day.ToString(System.Threading.Thread.CurrentThread.CurrentUICulture);
day++;
}
}
}
// There is an extra day we need to write
init = 0;
string previousDay;
while (daysInMonth >= day)
{
previousDay = tableLayoutPanel1.GetControlFromPosition(init, 5).Text;
tableLayoutPanel1.GetControlFromPosition(init, 5).Text = previousDay + "/" + day.ToString(System.Threading.Thread.CurrentThread.CurrentUICulture);
day++;
init++;
}
}