using System;
using System.Configuration;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
using System.Windows.Forms;
namespace FadingForm
{
public partial class FrmSplashScreen : Form
{
bool fadeForm;
Timer fadeTimer;
int fadeDuration;
int fadeStages;
WindowStatus status;
public FrmSplashScreen()
{
InitializeComponent();
}
protected override void OnLoad(EventArgs e)
{
this.fadeForm = Boolean.Parse(ConfigurationManager.AppSettings["FadeForm"]);
if (this.fadeForm)
{
this.fadeDuration = Int32.Parse(ConfigurationManager.AppSettings["FadeDuration"]);
this.fadeStages = Int32.Parse(ConfigurationManager.AppSettings["FadeStages"]);
this.fadeTimer = new Timer();
this.fadeTimer.Enabled = true;
this.fadeTimer.Interval = fadeDuration / fadeStages;
this.fadeTimer.Tick += new EventHandler(fadeTimer_Tick);
this.status = WindowStatus.Opening;
this.Opacity = 0;
this.fadeTimer.Start();
}
base.OnLoad(e);
}
void fadeTimer_Tick(object sender, EventArgs e)
{
switch (this.status)
{
case WindowStatus.Opening:
if (this.Opacity < 1)
this.Opacity += (double)1 / (double)this.fadeStages;
else
this.fadeTimer.Stop();
break;
case WindowStatus.Closing:
if (this.Opacity > 0)
this.Opacity -= (double)1 / (double)this.fadeStages;
else
{
this.fadeTimer.Stop();
this.fadeForm = false;
this.Close();
}
break;
}
}
protected override void OnClosing(CancelEventArgs e)
{
if (this.fadeForm)
{
e.Cancel = true;
this.status = WindowStatus.Closing;
this.fadeTimer.Start();
}
}
}
public enum WindowStatus
{
Opening,
Closing
}
}
I've been involved in object-oriented software development since 2006, when I graduated in Information and TLC Engineering. I've been working for several software companies / departments, mainly on Microsoft and Sun/Oracle technologies. My favourite programming language is C#, next comes Java.
I love design patterns and when I need to resolve a problem, I try to get the best solution, which is often not the quickest one.
"On the best teams, different individuals provide occasional leadership, taking charge in areas where they have particular strengths. No one is the permanent leader, because that person would then cease to be a peer and the team interaction would begin to break down. The structure of a team is a network, not a hierarchy ..."
My favourite team work quotation by DeMarco - Lister in Peopleware