This is the basic class that I am trying to display:

public class Day
{
public DateTime Date { get; private set; }

public SpecialDay SpecialDay { get; set; }

public DateTime TimeIn { get; private set; }

public DateTime TimeOut { get; private set; }

public DayOfWeek DayOfWeek

public TimeSpan TotalHours
}


It is contained inside a list in in following class:

public class Month
{
private int _month { get; set; }
private int _year { get; set; }

public DateTime Date

public List<Day> Days { get; private set; }

public TimeSpan TotalHoursInMonth
}


This is the load function of the main display form

private void MonthDataForm_Load(object sender, EventArgs e)
{
int bottomOfPreviousDay = -1;

foreach (var item in MonthDisplaying.Days)
{
DayView dayDisplay = new DayView(item);

if (bottomOfPreviousDay == -1)
{
dayDisplay.Top = this.Top + 10;
}
else
{
dayDisplay.Top = bottomOfPreviousDay + 2;
}

bottomOfPreviousDay = dayDisplay.Bottom;
}

this.WindowState = FormWindowState.Maximized;
}


The form shows a list of days for a given month like so

Each line is a separate instance of the Day class, and in the next stage of development there will be buttons to perform different actions on each instance.

Is there a better way for calculating the position of the user controls that are being added? I don't like the way the if/else looks but I am not sure how else to do it.

• Can you add some more context? What exactly are you trying to accomplish here? Are you stacking each of the days on top of eachother? Maybe a screenshot would help too. – Steve Michael Oct 5 '14 at 13:14

As you seem to specifically ask for: Is there a better way for calculating the position of the user controls that are being added? I don't like the way the if/else looks but I am not sure how else to do it.

My answer will address only this. You can make a better use of the variable and instead of -1 use Top + 10 and later = Bottom + 2. The code:

    int nextTop = this.Top + 10;

foreach (var item in MonthDisplaying.Days)
{
DayView dayDisplay = new DayView(item);

dayDisplay.Top = nextTop;

nextTop = dayDisplay.Bottom + 2;