2
\$\begingroup\$

I have recently picked up c# using visual studio and set myself a project to create a weather application. I would like a peer review of my code so I find areas where I can improve and learn more best practices.

mainFrame.cs

using System;
using System.Drawing;
using System.Windows.Forms;

namespace SmartMirror
{
    public partial class mainFrame : Form
    {
        bool FullScreenMode = false;
        Weather weather;

        public mainFrame()
        {
            InitializeComponent();
            // Start the one second timer          
            timerSecond.Start();
            timerSecond.Enabled = true;
            timerSecond.Interval = 1000;
            // Start the ten minute timer
            timer10Minutes.Start();
            timer10Minutes.Enabled = true;
            timer10Minutes.Interval = 600000;
        }

        // Set some keyboard shortcuts for the application
        // Escape - closes the application
        // Enter - Toggles between the application being full screen.
        protected override bool ProcessDialogKey(Keys keyData)
        {
            if (Form.ModifierKeys == Keys.None && keyData == Keys.Escape)
            {
                this.Close();
                return true;
            }
            else if (keyData == Keys.Enter)
            {
                if (FullScreenMode)
                {
                    FullScreenMode = false;
                    this.FormBorderStyle = FormBorderStyle.FixedSingle;
                    this.WindowState = FormWindowState.Normal;
                }
                else
                {
                    FullScreenMode = true;
                    this.FormBorderStyle = FormBorderStyle.None;
                    this.WindowState = FormWindowState.Maximized;
                }
            }
            return base.ProcessDialogKey(keyData);
        }

        // Intially load tyhe weather class and labels. 
        private void mainFrame_Load(object sender, EventArgs e)
        {

            weather = new Weather();
            updateWeatherLabels();
        }

        // Updates the text of the labels 
        public void updateWeatherLabels()
        {
            weather = new Weather();

            currentTempLabel.Text = weather.currentTemp.ToString("0") + "°";
            weatherIcon.Image = (Image)Properties.Resources.ResourceManager.GetObject(weather.currentIcon);
            apperantTemperatureLabel.Text = "Feels like: " + weather.currentApparentTemp.ToString("0") + "°";

            locationLabel.Text = weather.city + ", " + weather.regionName;
            windLabel.Text = weather.direction + " " + weather.currentWindSpeed.ToString("0") + " mph";
            humidityLabel.Text = weather.currentHumidity.ToString("P0");
            precipitationLabel.Text = weather.currentPrecipitation.ToString("P0");
            cloudCoverLabel.Text = weather.currentCloudCover.ToString("P0");
            sunriseLabel.Text = weather.convertSunriseTime.ToString();
            sunsetLabel.Text = weather.convertSunsetTime.ToString();

            day1Label.Text = DateTime.Now.AddDays(1).ToString("dddd");
            day2Label.Text = DateTime.Now.AddDays(2).ToString("dddd");
            day3Label.Text = DateTime.Now.AddDays(3).ToString("dddd");
            day4Label.Text = DateTime.Now.AddDays(4).ToString("dddd");

            day1MinLabel.Text = weather.forecast1Day.MinTemp.ToString("0") + "°";
            day2MinLabel.Text = weather.forecast2Day.MinTemp.ToString("0") + "°";
            day3MinLabel.Text = weather.forecast3Day.MinTemp.ToString("0") + "°";
            day4MinLabel.Text = weather.forecast4Day.MinTemp.ToString("0") + "°";

            day1MaxLabel.Text = weather.forecast1Day.MaxTemp.ToString("0") + "°";
            day2MaxLabel.Text = weather.forecast2Day.MaxTemp.ToString("0") + "°";
            day3MaxLabel.Text = weather.forecast3Day.MaxTemp.ToString("0") + "°";
            day4MaxLabel.Text = weather.forecast4Day.MaxTemp.ToString("0") + "°";

            day1PictureBox.Image = (Image)Properties.Resources.ResourceManager.GetObject(weather.forecast1Day.Icon);
            day2PictureBox.Image = (Image)Properties.Resources.ResourceManager.GetObject(weather.forecast2Day.Icon);
            day3PictureBox.Image = (Image)Properties.Resources.ResourceManager.GetObject(weather.forecast3Day.Icon);
            day4PictureBox.Image = (Image)Properties.Resources.ResourceManager.GetObject(weather.forecast4Day.Icon);
        }

        // Every one second the text of the date and time labels update
        private void timerSecond_Tick(object sender, EventArgs e)
        {
            currentDate.Text = DateTime.Now.ToString("dddd, dd MMMM yyyy");
            currentTime.Text = DateTime.Now.ToLocalTime().ToShortTimeString();
        }

        // Every ten minutes the labels for the weather application update
        private void timer10Minutes_Tick(object sender, EventArgs e)
        {
            weather = new Weather();
            updateWeatherLabels();
        }
    }
}

Weather.cs

using System;
using ForecastIO;
using System.Xml;
using System.Xml.Serialization;

namespace SmartMirror
{
    public class Weather
    {
        public string currentIcon;
        public string direction;
        public float currentWindSpeed;
        public float currentWindBearing;
        public float currentTemp;
        public float currentApparentTemp;
        public float currentHumidity;
        public float currentCloudCover;
        public float currentPrecipitation;
        public long currentSunriseTime;
        public string convertSunriseTime;
        public long currentSunsetTime;
        public string convertSunsetTime;
        public double bearing;

        public Forecast forecast1Day;
        public Forecast forecast2Day;
        public Forecast forecast3Day;
        public Forecast forecast4Day;

        public string regionName;
        public string city;
        public string latitude;
        public string longitude;
        public float newLatitude;
        public float newLongitude;

        public Weather()
        {
            XmlSerializer serializer = new XmlSerializer(typeof(Response));
            XmlTextReader reader = new XmlTextReader("https://freegeoip.net/xml/");
            Response location = (Response)serializer.Deserialize(reader);

            regionName = location.RegionName;
            city = location.City;
            latitude = location.Latitude;
            longitude = location.Longitude;
            newLatitude = (float)Convert.ToSingle(latitude);
            newLongitude = (float)Convert.ToSingle(longitude);

            var request = new ForecastIORequest("ApiKey", newLatitude, newLongitude, DateTime.Now, Unit.uk);
            var response = request.Get();

            currentIcon = response.currently.icon;
            currentTemp = response.currently.temperature;
            currentApparentTemp = response.currently.apparentTemperature;
            currentWindSpeed = response.currently.windSpeed;
            currentWindBearing = response.currently.windBearing;
            currentHumidity = response.currently.humidity;
            currentCloudCover = response.currently.cloudCover;
            currentPrecipitation = response.currently.precipProbability;
            currentSunriseTime = response.daily.data[0].sunriseTime;
            currentSunsetTime = response.daily.data[0].sunsetTime;

            forecast1Day = GetForecast(1);
            forecast2Day = GetForecast(2);
            forecast3Day = GetForecast(3);
            forecast4Day = GetForecast(4);

            bearing = Convert.ToDouble(currentWindBearing);
            bearing = ((bearing + ((360 / 16) / 2)) / (360 / 16));
            bearing = Math.Round(bearing,0);
            bearing = bearing == 16 ? 0 : bearing;
            Compass status = (Compass)bearing;
            direction = status.ToString();

            convertSunriseTime = UnixTimeStampToDateTime(currentSunriseTime).ToString("hh\\:mm");
            convertSunsetTime = UnixTimeStampToDateTime(currentSunsetTime).ToString("hh\\:mm");

        }

        public Forecast GetForecast(int dayToAdd)
        {
            var request = new ForecastIORequest("ApiKey", newLatitude, newLongitude, DateTime.Now.AddDays(dayToAdd), Unit.uk);
            var response = request.Get();
            Forecast forecast = new Forecast();
            forecast.Icon = response.daily.data[0].icon;
            forecast.MinTemp = response.daily.data[0].temperatureMin;
            forecast.MaxTemp = response.daily.data[0].temperatureMax;
            return forecast;
        }

        private static TimeSpan UnixTimeStampToDateTime(long unixTimeStamp)
        {
            DateTime dtDateTime = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc);
            dtDateTime = dtDateTime.AddSeconds(unixTimeStamp);
            return dtDateTime.TimeOfDay;
        }

    }
}

Location.cs

namespace SmartMirror
{
    public class Response
    {
        public string IP { get; set; }
        public string CountryCode { get; set; }
        public string CountryName { get; set; }
        public string RegionCode { get; set; }
        public string RegionName { get; set; }
        public string City { get; set; }
        public string ZipCode { get; set; }
        public string TimeZone { get; set; }
        public string Latitude { get; set; }
        public string Longitude { get; set; }
        public string MetroCode { get; set; }
    }
}

Forecast.cs

namespace SmartMirror
{
    public class Forecast
    {
        public string Icon { get; set; }
        public float MaxTemp { get; set; }
        public float MinTemp { get; set; }
    }
}

Compass.cs

namespace SmartMirror
{
    public enum Compass
    {
        S = 0,
        SSW = 1,
        SW = 2,
        WSW = 3,
        W = 4,
        WNW = 5,
        NW = 6,
        NNW = 7,
        N = 8,
        NNE = 9,
        NE = 10,
        ENE = 11,
        E = 12,
        ESE = 13,
        SE = 14,
        SSE = 15,
    }
}

mainFrame.Designer.cs

namespace SmartMirror
{
    partial class mainFrame
    {
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Windows Form Designer generated code

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.components = new System.ComponentModel.Container();
            this.currentDate = new System.Windows.Forms.Label();
            this.currentTime = new System.Windows.Forms.Label();
            this.timerSecond = new System.Windows.Forms.Timer(this.components);
            this.weatherIcon = new System.Windows.Forms.PictureBox();
            this.currentTempLabel = new System.Windows.Forms.Label();
            this.apperantTemperatureLabel = new System.Windows.Forms.Label();
            this.weatherPanel = new System.Windows.Forms.Panel();
            this.day4PictureBox = new System.Windows.Forms.PictureBox();
            this.day3PictureBox = new System.Windows.Forms.PictureBox();
            this.day2PictureBox = new System.Windows.Forms.PictureBox();
            this.day1PictureBox = new System.Windows.Forms.PictureBox();
            this.day4MinLabel = new System.Windows.Forms.Label();
            this.day3MinLabel = new System.Windows.Forms.Label();
            this.day2MinLabel = new System.Windows.Forms.Label();
            this.day1MinLabel = new System.Windows.Forms.Label();
            this.day4MaxLabel = new System.Windows.Forms.Label();
            this.day3MaxLabel = new System.Windows.Forms.Label();
            this.day2MaxLabel = new System.Windows.Forms.Label();
            this.day1MaxLabel = new System.Windows.Forms.Label();
            this.lowTitle = new System.Windows.Forms.Label();
            this.highTitle = new System.Windows.Forms.Label();
            this.day3Label = new System.Windows.Forms.Label();
            this.day4Label = new System.Windows.Forms.Label();
            this.day1Label = new System.Windows.Forms.Label();
            this.day2Label = new System.Windows.Forms.Label();
            this.windLabel = new System.Windows.Forms.Label();
            this.locationLabel = new System.Windows.Forms.Label();
            this.humidityLabel = new System.Windows.Forms.Label();
            this.humidityTitle = new System.Windows.Forms.Label();
            this.cloudCoverTitle = new System.Windows.Forms.Label();
            this.precipitationLabel = new System.Windows.Forms.Label();
            this.locationTitle = new System.Windows.Forms.Label();
            this.windTitle = new System.Windows.Forms.Label();
            this.precepitationTitle = new System.Windows.Forms.Label();
            this.cloudCoverLabel = new System.Windows.Forms.Label();
            this.timer10Minutes = new System.Windows.Forms.Timer(this.components);
            this.panel1 = new System.Windows.Forms.Panel();
            this.day0MinMaxLabel = new System.Windows.Forms.Label();
            this.sunLabel = new System.Windows.Forms.Label();
            ((System.ComponentModel.ISupportInitialize)(this.weatherIcon)).BeginInit();
            this.weatherPanel.SuspendLayout();
            ((System.ComponentModel.ISupportInitialize)(this.day4PictureBox)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.day3PictureBox)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.day2PictureBox)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.day1PictureBox)).BeginInit();
            this.SuspendLayout();
            // 
            // currentDate
            // 
            this.currentDate.Anchor = System.Windows.Forms.AnchorStyles.Left;
            this.currentDate.AutoSize = true;
            this.currentDate.Font = new System.Drawing.Font("Microsoft Sans Serif", 24F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.currentDate.ForeColor = System.Drawing.SystemColors.ControlLightLight;
            this.currentDate.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
            this.currentDate.Location = new System.Drawing.Point(12, 12);
            this.currentDate.Name = "currentDate";
            this.currentDate.RightToLeft = System.Windows.Forms.RightToLeft.No;
            this.currentDate.Size = new System.Drawing.Size(482, 37);
            this.currentDate.TabIndex = 0;
            this.currentDate.Text = "Wednesday, 08 September 2017";
            this.currentDate.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
            // 
            // currentTime
            // 
            this.currentTime.Anchor = System.Windows.Forms.AnchorStyles.Left;
            this.currentTime.AutoSize = true;
            this.currentTime.BackColor = System.Drawing.SystemColors.WindowText;
            this.currentTime.Font = new System.Drawing.Font("Microsoft Sans Serif", 42F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.currentTime.ForeColor = System.Drawing.SystemColors.ControlLightLight;
            this.currentTime.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
            this.currentTime.Location = new System.Drawing.Point(8, 49);
            this.currentTime.Name = "currentTime";
            this.currentTime.RightToLeft = System.Windows.Forms.RightToLeft.No;
            this.currentTime.Size = new System.Drawing.Size(168, 64);
            this.currentTime.TabIndex = 1;
            this.currentTime.Text = "00:00";
            this.currentTime.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
            // 
            // timerSecond
            // 
            this.timerSecond.Tick += new System.EventHandler(this.timerSecond_Tick);
            // 
            // weatherIcon
            // 
            this.weatherIcon.Anchor = System.Windows.Forms.AnchorStyles.None;
            this.weatherIcon.Image = global::SmartMirror.Properties.Resources.clear_day;
            this.weatherIcon.Location = new System.Drawing.Point(2, 0);
            this.weatherIcon.Name = "weatherIcon";
            this.weatherIcon.Size = new System.Drawing.Size(152, 140);
            this.weatherIcon.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
            this.weatherIcon.TabIndex = 2;
            this.weatherIcon.TabStop = false;
            // 
            // currentTempLabel
            // 
            this.currentTempLabel.Anchor = System.Windows.Forms.AnchorStyles.Left;
            this.currentTempLabel.Font = new System.Drawing.Font("Microsoft Sans Serif", 63.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.currentTempLabel.ForeColor = System.Drawing.SystemColors.ControlLightLight;
            this.currentTempLabel.Location = new System.Drawing.Point(150, 0);
            this.currentTempLabel.Name = "currentTempLabel";
            this.currentTempLabel.Size = new System.Drawing.Size(178, 140);
            this.currentTempLabel.TabIndex = 3;
            this.currentTempLabel.Text = "99°";
            this.currentTempLabel.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // apperantTemperatureLabel
            // 
            this.apperantTemperatureLabel.Anchor = System.Windows.Forms.AnchorStyles.None;
            this.apperantTemperatureLabel.Font = new System.Drawing.Font("Microsoft YaHei UI", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.apperantTemperatureLabel.ForeColor = System.Drawing.SystemColors.ControlLightLight;
            this.apperantTemperatureLabel.Location = new System.Drawing.Point(2, 203);
            this.apperantTemperatureLabel.Name = "apperantTemperatureLabel";
            this.apperantTemperatureLabel.Size = new System.Drawing.Size(326, 30);
            this.apperantTemperatureLabel.TabIndex = 4;
            this.apperantTemperatureLabel.Text = "Feels like: 99°";
            this.apperantTemperatureLabel.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
            // 
            // weatherPanel
            // 
            this.weatherPanel.Anchor = System.Windows.Forms.AnchorStyles.None;
            this.weatherPanel.Controls.Add(this.sunLabel);
            this.weatherPanel.Controls.Add(this.day0MinMaxLabel);
            this.weatherPanel.Controls.Add(this.day4PictureBox);
            this.weatherPanel.Controls.Add(this.day3PictureBox);
            this.weatherPanel.Controls.Add(this.day2PictureBox);
            this.weatherPanel.Controls.Add(this.day1PictureBox);
            this.weatherPanel.Controls.Add(this.day4MinLabel);
            this.weatherPanel.Controls.Add(this.day3MinLabel);
            this.weatherPanel.Controls.Add(this.day2MinLabel);
            this.weatherPanel.Controls.Add(this.day1MinLabel);
            this.weatherPanel.Controls.Add(this.day4MaxLabel);
            this.weatherPanel.Controls.Add(this.day3MaxLabel);
            this.weatherPanel.Controls.Add(this.day2MaxLabel);
            this.weatherPanel.Controls.Add(this.day1MaxLabel);
            this.weatherPanel.Controls.Add(this.lowTitle);
            this.weatherPanel.Controls.Add(this.highTitle);
            this.weatherPanel.Controls.Add(this.day3Label);
            this.weatherPanel.Controls.Add(this.day4Label);
            this.weatherPanel.Controls.Add(this.day1Label);
            this.weatherPanel.Controls.Add(this.day2Label);
            this.weatherPanel.Controls.Add(this.currentTempLabel);
            this.weatherPanel.Controls.Add(this.windLabel);
            this.weatherPanel.Controls.Add(this.locationLabel);
            this.weatherPanel.Controls.Add(this.humidityLabel);
            this.weatherPanel.Controls.Add(this.humidityTitle);
            this.weatherPanel.Controls.Add(this.cloudCoverTitle);
            this.weatherPanel.Controls.Add(this.apperantTemperatureLabel);
            this.weatherPanel.Controls.Add(this.precipitationLabel);
            this.weatherPanel.Controls.Add(this.locationTitle);
            this.weatherPanel.Controls.Add(this.weatherIcon);
            this.weatherPanel.Controls.Add(this.windTitle);
            this.weatherPanel.Controls.Add(this.precepitationTitle);
            this.weatherPanel.Controls.Add(this.cloudCoverLabel);
            this.weatherPanel.Location = new System.Drawing.Point(722, 12);
            this.weatherPanel.Name = "weatherPanel";
            this.weatherPanel.Size = new System.Drawing.Size(330, 619);
            this.weatherPanel.TabIndex = 5;
            // 
            // day4PictureBox
            // 
            this.day4PictureBox.Location = new System.Drawing.Point(151, 558);
            this.day4PictureBox.Name = "day4PictureBox";
            this.day4PictureBox.Size = new System.Drawing.Size(30, 30);
            this.day4PictureBox.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
            this.day4PictureBox.TabIndex = 41;
            this.day4PictureBox.TabStop = false;
            // 
            // day3PictureBox
            // 
            this.day3PictureBox.Location = new System.Drawing.Point(151, 528);
            this.day3PictureBox.Name = "day3PictureBox";
            this.day3PictureBox.Size = new System.Drawing.Size(30, 30);
            this.day3PictureBox.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
            this.day3PictureBox.TabIndex = 40;
            this.day3PictureBox.TabStop = false;
            // 
            // day2PictureBox
            // 
            this.day2PictureBox.Location = new System.Drawing.Point(151, 498);
            this.day2PictureBox.Name = "day2PictureBox";
            this.day2PictureBox.Size = new System.Drawing.Size(30, 30);
            this.day2PictureBox.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
            this.day2PictureBox.TabIndex = 39;
            this.day2PictureBox.TabStop = false;
            // 
            // day1PictureBox
            // 
            this.day1PictureBox.Location = new System.Drawing.Point(151, 468);
            this.day1PictureBox.Name = "day1PictureBox";
            this.day1PictureBox.Size = new System.Drawing.Size(30, 30);
            this.day1PictureBox.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
            this.day1PictureBox.TabIndex = 6;
            this.day1PictureBox.TabStop = false;
            // 
            // day4MinLabel
            // 
            this.day4MinLabel.Anchor = System.Windows.Forms.AnchorStyles.Right;
            this.day4MinLabel.Font = new System.Drawing.Font("Microsoft YaHei UI", 14.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.day4MinLabel.ForeColor = System.Drawing.SystemColors.ControlLightLight;
            this.day4MinLabel.Location = new System.Drawing.Point(187, 558);
            this.day4MinLabel.Name = "day4MinLabel";
            this.day4MinLabel.Size = new System.Drawing.Size(67, 30);
            this.day4MinLabel.TabIndex = 38;
            this.day4MinLabel.Text = "00°";
            this.day4MinLabel.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // day3MinLabel
            // 
            this.day3MinLabel.Anchor = System.Windows.Forms.AnchorStyles.Right;
            this.day3MinLabel.Font = new System.Drawing.Font("Microsoft YaHei UI", 14.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.day3MinLabel.ForeColor = System.Drawing.SystemColors.ControlLightLight;
            this.day3MinLabel.Location = new System.Drawing.Point(187, 528);
            this.day3MinLabel.Name = "day3MinLabel";
            this.day3MinLabel.Size = new System.Drawing.Size(67, 30);
            this.day3MinLabel.TabIndex = 37;
            this.day3MinLabel.Text = "00°";
            this.day3MinLabel.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // day2MinLabel
            // 
            this.day2MinLabel.Anchor = System.Windows.Forms.AnchorStyles.Right;
            this.day2MinLabel.Font = new System.Drawing.Font("Microsoft YaHei UI", 14.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.day2MinLabel.ForeColor = System.Drawing.SystemColors.ControlLightLight;
            this.day2MinLabel.Location = new System.Drawing.Point(187, 498);
            this.day2MinLabel.Name = "day2MinLabel";
            this.day2MinLabel.Size = new System.Drawing.Size(67, 30);
            this.day2MinLabel.TabIndex = 36;
            this.day2MinLabel.Text = "00°";
            this.day2MinLabel.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // day1MinLabel
            // 
            this.day1MinLabel.Anchor = System.Windows.Forms.AnchorStyles.Right;
            this.day1MinLabel.Font = new System.Drawing.Font("Microsoft YaHei UI", 14.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.day1MinLabel.ForeColor = System.Drawing.SystemColors.ControlLightLight;
            this.day1MinLabel.Location = new System.Drawing.Point(187, 468);
            this.day1MinLabel.Name = "day1MinLabel";
            this.day1MinLabel.Size = new System.Drawing.Size(67, 30);
            this.day1MinLabel.TabIndex = 35;
            this.day1MinLabel.Text = "00°";
            this.day1MinLabel.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // day4MaxLabel
            // 
            this.day4MaxLabel.Anchor = System.Windows.Forms.AnchorStyles.Right;
            this.day4MaxLabel.Font = new System.Drawing.Font("Microsoft YaHei UI", 14.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.day4MaxLabel.ForeColor = System.Drawing.SystemColors.ControlLightLight;
            this.day4MaxLabel.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
            this.day4MaxLabel.Location = new System.Drawing.Point(260, 558);
            this.day4MaxLabel.Name = "day4MaxLabel";
            this.day4MaxLabel.Size = new System.Drawing.Size(67, 30);
            this.day4MaxLabel.TabIndex = 34;
            this.day4MaxLabel.Text = "99°";
            this.day4MaxLabel.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // day3MaxLabel
            // 
            this.day3MaxLabel.Anchor = System.Windows.Forms.AnchorStyles.Right;
            this.day3MaxLabel.Font = new System.Drawing.Font("Microsoft YaHei UI", 14.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.day3MaxLabel.ForeColor = System.Drawing.SystemColors.ControlLightLight;
            this.day3MaxLabel.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
            this.day3MaxLabel.Location = new System.Drawing.Point(260, 528);
            this.day3MaxLabel.Name = "day3MaxLabel";
            this.day3MaxLabel.Size = new System.Drawing.Size(67, 30);
            this.day3MaxLabel.TabIndex = 33;
            this.day3MaxLabel.Text = "99°";
            this.day3MaxLabel.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // day2MaxLabel
            // 
            this.day2MaxLabel.Anchor = System.Windows.Forms.AnchorStyles.Right;
            this.day2MaxLabel.Font = new System.Drawing.Font("Microsoft YaHei UI", 14.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.day2MaxLabel.ForeColor = System.Drawing.SystemColors.ControlLightLight;
            this.day2MaxLabel.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
            this.day2MaxLabel.Location = new System.Drawing.Point(260, 498);
            this.day2MaxLabel.Name = "day2MaxLabel";
            this.day2MaxLabel.Size = new System.Drawing.Size(67, 30);
            this.day2MaxLabel.TabIndex = 32;
            this.day2MaxLabel.Text = "99°";
            this.day2MaxLabel.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // day1MaxLabel
            // 
            this.day1MaxLabel.Anchor = System.Windows.Forms.AnchorStyles.Right;
            this.day1MaxLabel.Font = new System.Drawing.Font("Microsoft YaHei UI", 14.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.day1MaxLabel.ForeColor = System.Drawing.SystemColors.ControlLightLight;
            this.day1MaxLabel.Location = new System.Drawing.Point(260, 468);
            this.day1MaxLabel.Name = "day1MaxLabel";
            this.day1MaxLabel.Size = new System.Drawing.Size(67, 30);
            this.day1MaxLabel.TabIndex = 31;
            this.day1MaxLabel.Text = "99°";
            this.day1MaxLabel.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // lowTitle
            // 
            this.lowTitle.Anchor = System.Windows.Forms.AnchorStyles.Right;
            this.lowTitle.Font = new System.Drawing.Font("Microsoft YaHei UI", 14.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.lowTitle.ForeColor = System.Drawing.SystemColors.ControlLightLight;
            this.lowTitle.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
            this.lowTitle.Location = new System.Drawing.Point(187, 438);
            this.lowTitle.Name = "lowTitle";
            this.lowTitle.Size = new System.Drawing.Size(67, 30);
            this.lowTitle.TabIndex = 24;
            this.lowTitle.Text = "Low";
            this.lowTitle.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // highTitle
            // 
            this.highTitle.Anchor = System.Windows.Forms.AnchorStyles.Right;
            this.highTitle.Font = new System.Drawing.Font("Microsoft YaHei UI", 14.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.highTitle.ForeColor = System.Drawing.SystemColors.ControlLightLight;
            this.highTitle.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
            this.highTitle.Location = new System.Drawing.Point(260, 438);
            this.highTitle.Name = "highTitle";
            this.highTitle.Size = new System.Drawing.Size(67, 30);
            this.highTitle.TabIndex = 23;
            this.highTitle.Text = "High";
            this.highTitle.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // day3Label
            // 
            this.day3Label.Font = new System.Drawing.Font("Microsoft YaHei UI", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.day3Label.ForeColor = System.Drawing.SystemColors.ControlLightLight;
            this.day3Label.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
            this.day3Label.Location = new System.Drawing.Point(5, 528);
            this.day3Label.Name = "day3Label";
            this.day3Label.Size = new System.Drawing.Size(126, 30);
            this.day3Label.TabIndex = 22;
            this.day3Label.Text = "Thursday";
            this.day3Label.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
            // 
            // day4Label
            // 
            this.day4Label.Font = new System.Drawing.Font("Microsoft YaHei UI", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.day4Label.ForeColor = System.Drawing.SystemColors.ControlLightLight;
            this.day4Label.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
            this.day4Label.Location = new System.Drawing.Point(5, 558);
            this.day4Label.Name = "day4Label";
            this.day4Label.Size = new System.Drawing.Size(126, 30);
            this.day4Label.TabIndex = 21;
            this.day4Label.Text = "Wednesday";
            this.day4Label.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
            // 
            // day1Label
            // 
            this.day1Label.Font = new System.Drawing.Font("Microsoft YaHei UI", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.day1Label.ForeColor = System.Drawing.SystemColors.ControlLightLight;
            this.day1Label.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
            this.day1Label.Location = new System.Drawing.Point(5, 468);
            this.day1Label.Name = "day1Label";
            this.day1Label.Size = new System.Drawing.Size(126, 30);
            this.day1Label.TabIndex = 19;
            this.day1Label.Text = "Monday";
            this.day1Label.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
            // 
            // day2Label
            // 
            this.day2Label.Font = new System.Drawing.Font("Microsoft YaHei UI", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.day2Label.ForeColor = System.Drawing.SystemColors.ControlLightLight;
            this.day2Label.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
            this.day2Label.Location = new System.Drawing.Point(5, 498);
            this.day2Label.Name = "day2Label";
            this.day2Label.Size = new System.Drawing.Size(126, 30);
            this.day2Label.TabIndex = 20;
            this.day2Label.Text = "Tuesday";
            this.day2Label.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
            // 
            // windLabel
            // 
            this.windLabel.Anchor = System.Windows.Forms.AnchorStyles.Right;
            this.windLabel.Font = new System.Drawing.Font("Microsoft YaHei UI", 14.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.windLabel.ForeColor = System.Drawing.SystemColors.ControlLightLight;
            this.windLabel.ImageAlign = System.Drawing.ContentAlignment.MiddleRight;
            this.windLabel.Location = new System.Drawing.Point(167, 303);
            this.windLabel.Name = "windLabel";
            this.windLabel.Size = new System.Drawing.Size(160, 30);
            this.windLabel.TabIndex = 9;
            this.windLabel.Text = "NWN 99 mph";
            this.windLabel.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // locationLabel
            // 
            this.locationLabel.Anchor = System.Windows.Forms.AnchorStyles.None;
            this.locationLabel.Font = new System.Drawing.Font("Microsoft YaHei UI", 15.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.locationLabel.ForeColor = System.Drawing.SystemColors.ControlLightLight;
            this.locationLabel.Location = new System.Drawing.Point(2, 173);
            this.locationLabel.Name = "locationLabel";
            this.locationLabel.Size = new System.Drawing.Size(326, 30);
            this.locationLabel.TabIndex = 18;
            this.locationLabel.Text = "St Albans, England";
            this.locationLabel.TextAlign = System.Drawing.ContentAlignment.TopCenter;
            // 
            // humidityLabel
            // 
            this.humidityLabel.Anchor = System.Windows.Forms.AnchorStyles.Right;
            this.humidityLabel.Font = new System.Drawing.Font("Microsoft YaHei UI", 14.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.humidityLabel.ForeColor = System.Drawing.SystemColors.ControlLightLight;
            this.humidityLabel.ImageAlign = System.Drawing.ContentAlignment.MiddleRight;
            this.humidityLabel.Location = new System.Drawing.Point(167, 333);
            this.humidityLabel.Name = "humidityLabel";
            this.humidityLabel.Size = new System.Drawing.Size(160, 30);
            this.humidityLabel.TabIndex = 10;
            this.humidityLabel.Text = "100 %";
            this.humidityLabel.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // humidityTitle
            // 
            this.humidityTitle.Font = new System.Drawing.Font("Microsoft YaHei UI", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.humidityTitle.ForeColor = System.Drawing.SystemColors.ControlLightLight;
            this.humidityTitle.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
            this.humidityTitle.Location = new System.Drawing.Point(3, 333);
            this.humidityTitle.Name = "humidityTitle";
            this.humidityTitle.Size = new System.Drawing.Size(160, 30);
            this.humidityTitle.TabIndex = 6;
            this.humidityTitle.Text = "Humidity:";
            this.humidityTitle.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
            // 
            // cloudCoverTitle
            // 
            this.cloudCoverTitle.Font = new System.Drawing.Font("Microsoft YaHei UI", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.cloudCoverTitle.ForeColor = System.Drawing.SystemColors.ControlLightLight;
            this.cloudCoverTitle.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
            this.cloudCoverTitle.Location = new System.Drawing.Point(3, 363);
            this.cloudCoverTitle.Name = "cloudCoverTitle";
            this.cloudCoverTitle.Size = new System.Drawing.Size(160, 30);
            this.cloudCoverTitle.TabIndex = 8;
            this.cloudCoverTitle.Text = "Cloud Cover:";
            this.cloudCoverTitle.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
            // 
            // precipitationLabel
            // 
            this.precipitationLabel.Anchor = System.Windows.Forms.AnchorStyles.Right;
            this.precipitationLabel.Font = new System.Drawing.Font("Microsoft YaHei UI", 14.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.precipitationLabel.ForeColor = System.Drawing.SystemColors.ControlLightLight;
            this.precipitationLabel.ImageAlign = System.Drawing.ContentAlignment.MiddleRight;
            this.precipitationLabel.Location = new System.Drawing.Point(167, 393);
            this.precipitationLabel.Name = "precipitationLabel";
            this.precipitationLabel.Size = new System.Drawing.Size(160, 30);
            this.precipitationLabel.TabIndex = 11;
            this.precipitationLabel.Text = "100 %";
            this.precipitationLabel.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // locationTitle
            // 
            this.locationTitle.Anchor = System.Windows.Forms.AnchorStyles.None;
            this.locationTitle.Font = new System.Drawing.Font("Microsoft YaHei UI", 15.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.locationTitle.ForeColor = System.Drawing.SystemColors.ControlLightLight;
            this.locationTitle.Location = new System.Drawing.Point(2, 143);
            this.locationTitle.Name = "locationTitle";
            this.locationTitle.Size = new System.Drawing.Size(326, 30);
            this.locationTitle.TabIndex = 17;
            this.locationTitle.Text = "Temperature at";
            this.locationTitle.TextAlign = System.Drawing.ContentAlignment.TopCenter;
            // 
            // windTitle
            // 
            this.windTitle.Font = new System.Drawing.Font("Microsoft YaHei UI", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.windTitle.ForeColor = System.Drawing.SystemColors.ControlLightLight;
            this.windTitle.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
            this.windTitle.Location = new System.Drawing.Point(3, 303);
            this.windTitle.Name = "windTitle";
            this.windTitle.Size = new System.Drawing.Size(160, 30);
            this.windTitle.TabIndex = 5;
            this.windTitle.Text = "Wind:";
            this.windTitle.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
            // 
            // precepitationTitle
            // 
            this.precepitationTitle.Font = new System.Drawing.Font("Microsoft YaHei UI", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.precepitationTitle.ForeColor = System.Drawing.SystemColors.ControlLightLight;
            this.precepitationTitle.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
            this.precepitationTitle.Location = new System.Drawing.Point(3, 393);
            this.precepitationTitle.Name = "precepitationTitle";
            this.precepitationTitle.Size = new System.Drawing.Size(160, 30);
            this.precepitationTitle.TabIndex = 7;
            this.precepitationTitle.Text = "Precipitation:";
            this.precepitationTitle.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
            // 
            // cloudCoverLabel
            // 
            this.cloudCoverLabel.Anchor = System.Windows.Forms.AnchorStyles.Right;
            this.cloudCoverLabel.Font = new System.Drawing.Font("Microsoft YaHei UI", 14.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.cloudCoverLabel.ForeColor = System.Drawing.SystemColors.ControlLightLight;
            this.cloudCoverLabel.ImageAlign = System.Drawing.ContentAlignment.MiddleRight;
            this.cloudCoverLabel.Location = new System.Drawing.Point(167, 363);
            this.cloudCoverLabel.Name = "cloudCoverLabel";
            this.cloudCoverLabel.Size = new System.Drawing.Size(160, 30);
            this.cloudCoverLabel.TabIndex = 12;
            this.cloudCoverLabel.Text = "100 %";
            this.cloudCoverLabel.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // panel1
            // 
            this.panel1.Location = new System.Drawing.Point(19, 116);
            this.panel1.Name = "panel1";
            this.panel1.Size = new System.Drawing.Size(690, 514);
            this.panel1.TabIndex = 6;
            // 
            // day0MinMaxLabel
            // 
            this.day0MinMaxLabel.Anchor = System.Windows.Forms.AnchorStyles.None;
            this.day0MinMaxLabel.Font = new System.Drawing.Font("Microsoft YaHei UI", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.day0MinMaxLabel.ForeColor = System.Drawing.SystemColors.ControlLightLight;
            this.day0MinMaxLabel.Location = new System.Drawing.Point(2, 233);
            this.day0MinMaxLabel.Name = "day0MinMaxLabel";
            this.day0MinMaxLabel.Size = new System.Drawing.Size(326, 30);
            this.day0MinMaxLabel.TabIndex = 42;
            this.day0MinMaxLabel.Text = "Low: 99°  High: 99°";
            this.day0MinMaxLabel.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
            // 
            // sunLabel
            // 
            this.sunLabel.Anchor = System.Windows.Forms.AnchorStyles.None;
            this.sunLabel.Font = new System.Drawing.Font("Microsoft YaHei UI", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.sunLabel.ForeColor = System.Drawing.SystemColors.ControlLightLight;
            this.sunLabel.Location = new System.Drawing.Point(2, 263);
            this.sunLabel.Name = "sunLabel";
            this.sunLabel.Size = new System.Drawing.Size(326, 30);
            this.sunLabel.TabIndex = 43;
            this.sunLabel.Text = "Sunrise: 05:59 Sunset: 18:59";
            this.sunLabel.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
            // 
            // mainFrame
            // 
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None;
            this.BackColor = System.Drawing.SystemColors.WindowText;
            this.ClientSize = new System.Drawing.Size(1064, 1882);
            this.Controls.Add(this.panel1);
            this.Controls.Add(this.weatherPanel);
            this.Controls.Add(this.currentTime);
            this.Controls.Add(this.currentDate);
            this.Name = "mainFrame";
            this.Text = "mainFrame";
            this.Load += new System.EventHandler(this.mainFrame_Load);
            ((System.ComponentModel.ISupportInitialize)(this.weatherIcon)).EndInit();
            this.weatherPanel.ResumeLayout(false);
            ((System.ComponentModel.ISupportInitialize)(this.day4PictureBox)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.day3PictureBox)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.day2PictureBox)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.day1PictureBox)).EndInit();
            this.ResumeLayout(false);
            this.PerformLayout();

        }

        #endregion

        private System.Windows.Forms.Label currentDate;
        private System.Windows.Forms.Label currentTime;
        private System.Windows.Forms.Timer timerSecond;
        private System.Windows.Forms.PictureBox weatherIcon;
        private System.Windows.Forms.Label currentTempLabel;
        private System.Windows.Forms.Label apperantTemperatureLabel;
        private System.Windows.Forms.Panel weatherPanel;
        private System.Windows.Forms.Label windTitle;
        private System.Windows.Forms.Label cloudCoverTitle;
        private System.Windows.Forms.Label precepitationTitle;
        private System.Windows.Forms.Label humidityTitle;
        private System.Windows.Forms.Label cloudCoverLabel;
        private System.Windows.Forms.Label precipitationLabel;
        private System.Windows.Forms.Label humidityLabel;
        private System.Windows.Forms.Label windLabel;
        private System.Windows.Forms.Label locationLabel;
        private System.Windows.Forms.Label locationTitle;
        private System.Windows.Forms.Label highTitle;
        private System.Windows.Forms.Label day3Label;
        private System.Windows.Forms.Label day4Label;
        private System.Windows.Forms.Label day1Label;
        private System.Windows.Forms.Label day2Label;
        private System.Windows.Forms.Label lowTitle;
        private System.Windows.Forms.Label day4MinLabel;
        private System.Windows.Forms.Label day3MinLabel;
        private System.Windows.Forms.Label day2MinLabel;
        private System.Windows.Forms.Label day1MinLabel;
        private System.Windows.Forms.Label day4MaxLabel;
        private System.Windows.Forms.Label day3MaxLabel;
        private System.Windows.Forms.Label day2MaxLabel;
        private System.Windows.Forms.Label day1MaxLabel;
        private System.Windows.Forms.PictureBox day4PictureBox;
        private System.Windows.Forms.PictureBox day3PictureBox;
        private System.Windows.Forms.PictureBox day2PictureBox;
        private System.Windows.Forms.PictureBox day1PictureBox;
        private System.Windows.Forms.Timer timer10Minutes;
        private System.Windows.Forms.Panel panel1;
        private System.Windows.Forms.Label day0MinMaxLabel;
        private System.Windows.Forms.Label sunLabel;
    }
}
\$\endgroup\$
  • \$\begingroup\$ Are you sure this is working code. You don't register and tick event handlers. I don't see where the timers are defined. \$\endgroup\$ – paparazzo Mar 14 '17 at 10:59
  • \$\begingroup\$ Is there a better way show you all my code without having to paste each individual pages code? \$\endgroup\$ – Ross Mar 14 '17 at 11:11
  • 2
    \$\begingroup\$ For the Compass enum, suggest you start with N as 0 and proceed clockwise which seems to conform to weather standards. See: en.wikipedia.org/wiki/Points_of_the_compass \$\endgroup\$ – Rick Davin Mar 14 '17 at 13:29
2
\$\begingroup\$

(I have to do this as an answer since I don't have enough reputation on this site yet.)

  1. For setting the timer intervals, I like to use this form for readability.

    timer.Interval = (int) TimeSpan.FromSeconds(1).TotalMilliseconds;
    timer.Interval = (int) TimeSpan.FromMinutes(10).TotalMilliseconds;
    
  2. I'm not sure why you are creating a new Weather object in mainFrame_Load() and updateWeatherLabels() and timer10Minutes_Tick(). You probably only need the one in updateWeatherLabels().
| improve this answer | |
\$\endgroup\$
2
\$\begingroup\$
day1Label.Text = DateTime.Now.AddDays(1).ToString("dddd");
day2Label.Text = DateTime.Now.AddDays(2).ToString("dddd");
day3Label.Text = DateTime.Now.AddDays(3).ToString("dddd");
day4Label.Text = DateTime.Now.AddDays(4).ToString("dddd");

This means you need arrays.

 Label[] dayLabels = new []
 {
     day1Label,
     // ...
 };

 var now = DateTime.Now;
 foreach(var item in dayLabels.Select((dayLabel, index) = new 
 {
     dayLabel, 
     offset = index + 1
 }))
 { 
     item.dayLabel.Text = now.AddDays(item.offset).ToString("dddd");
 }
| improve this answer | |
\$\endgroup\$
1
\$\begingroup\$

Design Approach

The first thing that strikes me is that the Weather class is very broadly named - this may seem like a silly point but a good name tells us a lot about what the class should (and shouldn't) be doing.
The second thing that strikes me is that it is doing too much.

One of the main goals of a good design is to support future change to the system. We will want to makes changes over time (the only system without change requests is the one that no-one uses) and a bit of up-front thought can prevent a lot of future problems.

Say we want to get the details of the weather from another source or compare weather reports from different sources, how easy would it be to do with the current design.

Now consider another design.

Instead of Weather we call the class WeatherReport. We add a IWeatherReportingService interface which is responsible for creating the weather reports, and add a WeatherReportRequest class with details of the request which will allow us to have a single API call where different weather sources may require different information in the request

public interface IWeatherReportingService
{
    WeatherReport GetWeatherReport(WeatherReportRequest request);
}

public class WeatherReportRequest
{
    public WeatherReportRequest(string longitude, string latitude){
        Longitude = longitude;
        Latitude = latitude;
    }
    public string Longitude {get;}
    public string Latitude {get;}
}

Notes:

  • We do not convert to floats in the request because different weather sources may required different formats.
  • In a more complete system we might have a Location type which would comprise the latitude, longitude and perhaps more details and we would pass that as part of the request

The WeatherReport class now becomes a passive data holder which can be sourced from anywhere but is still pretty fragile.

We have forecasts for 4 days... what happens if we want to add a 5th?

//...
public Forecast forecast1Day;
public Forecast forecast2Day;
public Forecast forecast3Day;
public Forecast forecast4Day;
//...

Another shape would be

public class WeatherReport
{
    //...
    private readonly IList<Forecast> _dailyForecasts;

    //...
    public WeatherReport()
    {
         //...
         _dailyForecasts = new List<Forecast>();
         //...
    }

    //...
    public IEumerable<Forecast> DailyForecasts => _dailyForecasts;

    public void AddDailyForecast(Forecast forecast)
    {
        _dailyForecasts.Add(forecast);
    }

    //...
}

Now the client code can iterate though the list and display as many/few of the daily forecasts as desired/available. If we have a source that provides daily forecasts for seven into the future our Weather report can handle this.

Note:All the public members of the class should use Pascal Casing and they should be properties rather that fields. The second part is a future-proofing exercise, allowing us to change the implementation of the member without having to change the client code.

Other Ideas

Unless a member is needed outside the class, it should be private - newLatitude and newLongitude seem to be purely internal.

Unless a member is needed outside the method, it should be declared in the method. bearing seems to be used only in the constructor and should be declared local to the method.

Try to keep the code in a method at the same level of abstraction, moving pieces out to separate functions to reduce method size and make them easier to follow

e.g

we could replace

//...
bearing = Convert.ToDouble(currentWindBearing);
bearing = ((bearing + ((360 / 16) / 2)) / (360 / 16));
bearing = Math.Round(bearing,0);
bearing = bearing == 16 ? 0 : bearing;
Compass status = (Compass)bearing;
direction = status.ToString();
//...

with

//...
direction = GetDirectionFromWindBearing(currentWindBearing);

with all the calculations placed in a separate function.

| improve this answer | |
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.