-
The window fade effect is mainly to enhance the user experience of the software. At present, the winform program has automatically equipped this function on Vista/Win7, so it can only be used on earlier versions of systems such as XP.
Let’s talk about the specific implementation :-)
1. Use the Timer control to control the transparency (Opacity) of the form.
/// <summary>
/// Display form
/// </summary>
private void ShowWin()
{
this.tsmiShowHide.Text = "Hide";
this.SetWindowState();
this.Opacity = 0;
//Open the window fade effect
Timer tStart = new Timer();
tStart.Interval = 100;
tStart.Tick += new EventHandler(tStart_Tick);
tStart.Start();
}
/// <summary>
///Hide the form
/// </summary>
private void HideWin()
{
this.tsmiShowHide.Text = "Show";
//Turn off the window fade effect
Timer tClose = new Timer();
tClose.Interval = 100;
tClose.Tick += new EventHandler(tClose_Tick);
tClose.Start();
}
/// <summary>
/// Turn off the form fade effect
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void tClose_Tick(object sender, EventArgs e)
{
// Transparency is reduced by 10% for each execution
this.Opacity -= 0.1;
if (this.Opacity <= 0)
{
((Timer)sender).Stop();
}
}
/// <summary>
/// Turn on the form fade effect
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void tStart_Tick(object sender, EventArgs e)
{
// Each execution transparency increases by 10%
this.Opacity += 0.1;
if (this.Opacity == 1)
{
((Timer)sender).Stop();
this.Focus();
}
}
Using the fade effect on EyesBaby is also a so-called test.
Summarize
Now that the EyesBaby function implementation part is written, this is the end of this section. I wrote part of it before, but it actually doesn’t have much technical content. My technical level is very good, and most of what I write can only be a way of self-recording, and cannot achieve the level of teaching by words and deeds. I hope you will learn a lot! There is a lot to learn, and some bloggers have made a lot of good suggestions. For example, the automatic update part. Thank you!
In the future, I hope to develop more personal software that is helpful to our work/life (I believe in "technology changes life"), and I also hope that everyone can provide more suggestions and technical help!
Download address: http://files.cnblogs.com/yizhuqing/EyesBabySetup10.zip
My first practical tool-eye protection program (EyesBaby)
EyesBaby1.0 usage help documentation
Window drag and zoom function implemented by EyesBaby function
EyesBaby function implementation: adding characters to the picture control
Windows foreground color adjuster implemented by EyesBaby function
Software update for EyesBaby function implementation