Personal Timeline

Personal TimelineAfter recently finding this British History Timeline, I decided to map out a brief history of Giles Bathgate. The first blue section represents my early childhood. Followed by a green section representing my Pre-school years. The orange section is my time at Secondary School, followed by the two years at college in yellow. The four years I spent at University are purple followed finally a blue section which represents working up to the present day. The red section at the end represents the range of years in which i might pass away due to natural causes.

I used the following code to generate the timeline image.

Option Strict On

Public Class Form1
	Private m_Start As Date = #11/10/1979#
	Private m_Finish As Date = #1/1/2070#
	Private m_StartPrimarySchool As Date = #1/1/1984#
	Private m_StartSecondarySchool As Date = #1/1/1991#
	Private m_StartCollege As Date = #1/1/1996#
	Private m_StartUniversity As Date = #1/1/1998#
	Private m_StartWork As Date = #1/1/2002#

	Private m_font As New Font("arial", 10, FontStyle.Regular, GraphicsUnit.Pixel)
	Private m_Steps As Integer
	Sub New()

		' This call is required by the Windows Form Designer.
		InitializeComponent()

		' Add any initialization after the InitializeComponent() call.
		Me.StartPosition = FormStartPosition.Manual
		Me.Location = New Point(0, 0)
		Me.Height = Screen.GetWorkingArea(New Point(0, 0)).Height
		Me.Width = 150

	End Sub
	Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
		MyBase.OnPaint(e)
		e.Graphics.Clear(Color.White)

		Dim years As Integer = m_Finish.Year - m_Start.Year
		m_Steps = Me.Height  years

		For i As Integer = 0 To years + 10
			e.Graphics.DrawLine(Pens.LightGray, 0, i * m_Steps, Me.Width, i * m_Steps)
		Next

		For i As Integer = 1 To years Step 10
			e.Graphics.DrawLine(Pens.Gray, 0, i * m_Steps, Me.Width, i * m_Steps)
			e.Graphics.DrawString(m_Start.AddYears(i).Year.ToString, m_font, Brushes.Black, 100, i * m_Steps)
		Next

		DrawRange(e.Graphics, m_Start, m_StartPrimarySchool, Color.LightBlue)
		DrawRange(e.Graphics, m_StartPrimarySchool, m_StartSecondarySchool, Color.Green)
		DrawRange(e.Graphics, m_StartSecondarySchool, m_StartCollege, Color.Orange)
		DrawRange(e.Graphics, m_StartCollege, m_StartUniversity, Color.Gold)
		DrawRange(e.Graphics, m_StartUniversity, m_StartWork, Color.Purple)
		DrawRange(e.Graphics, m_StartWork, Now, Color.Blue)

		DrawRange(e.Graphics, m_Start.AddYears(74), m_Start.AddYears(90), Color.Red)
		Dim nowyear As Integer = Now.Year - m_Start.Year
		e.Graphics.DrawLine(Pens.Blue, 0, nowyear * m_Steps, 200, nowyear * m_Steps)
		e.Graphics.DrawString(Now.Year.ToString, m_font, Brushes.Blue, 100, nowyear * m_Steps)
	End Sub

	Private Sub DrawRange(ByVal g As Graphics, ByVal start As Date, ByVal endy As Date, ByVal c As Color)
		Dim startyear As Integer = start.Year - m_Start.Year
		Dim endyear As Integer = endy.Year - m_Start.Year
		Using b As New SolidBrush(Color.FromArgb(100, c))
			g.FillRectangle(b, 0, startyear * m_Steps, 50, (endyear - startyear) * m_Steps)
		End Using
	End Sub

	Protected Overrides Sub OnResize(ByVal e As System.EventArgs)
		MyBase.OnResize(e)
		Me.Invalidate()
	End Sub
End Class
Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s