用C#做出像金山毒霸2012SP3.5的关闭窗口的效果

dali_yan 2012-04-10 08:46:57
我写了一段代码,不过不是很好,没它的漂亮,大家出出主意。
我的代码如下:

using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;

namespace 透明渐变效果
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();

}

private void timer1_Tick(object sender, EventArgs e)//透明渐变效果
{
if (true)
{
if (Opacity + 0.1 >= 1.0)
{
Opacity -= 0.1;

}
else
{
Opacity = 0.0;
timer1.Stop();

}

}
else
{

if(Opacity - 0.1<= 0.0)
{
Opacity = 0.0;
timer1.Stop();


}
else
{
Opacity -= 0.1;


}

}
}

private void toolStripProgressBar1_Click(object sender, EventArgs e)
{

}



private void timer2_Tick(object sender, EventArgs e)//窗口渐变效果
{

int d = 45;

if (true)
{
if (Height + d >= 450)
{
Height -= d;

}
else
{
Height = 0;
timer2.Stop();

}
}
else
{

if(Height - d <= 0)
{
Height = 0;
timer1.Stop();

}
else
{
Height -= d;
}
}



}

private void Form1_KeyPress(object sender, KeyPressEventArgs e)
{


}

private void Form1_Load(object sender, EventArgs e)
{


}

private void button1_Click(object sender, EventArgs e)
{


Height = 450;
timer2.Start();//窗口渐变效果
Opacity = 1.0;
timer1.Start();//透明度效果



}







}
}
timer1和timer2的Interval的值都设为200,点击按钮1就可以看到效果
我看的金山毒霸是窗体收缩的速度好像是越来越快的,应该收缩速度也是要渐变的,第二个是在关闭窗体的formclosing事件中,但我把代码放过去效果没有出现前窗体就被关闭了。

...全文
277 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
fenghuanb5 2012-07-27
  • 打赏
  • 举报
回复
protected override void OnClosing(System.ComponentModel.CancelEventArgs e)
{
base.OnClosing(e);
while (true)
{
if (this.Height <= 2)
break;
if (this.Opacity > 0)
this.Opacity -= 0.003;
this.Top += 5;
this.Height -= 10;
}
this.Dispose();
this.Close();
Application.Exit();
}
mrsupersky 2012-05-17
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 的回复:]

引用 8 楼 的回复:

引用 7 楼 的回复:

为什么不用wpf。。。。

WPF 麻烦...


你竟然说WPF麻烦…………winform做出来的动画效果很生硬的,他们本身就是用的WPF,比如迅雷
[/Quote]

据了解迅雷并未使用WPF,而是有一套自己开发的UI系统,谢谢....

UpdateLayeredWindow...函数
岁月无情_1 2012-04-11
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 的回复:]

引用 7 楼 的回复:

为什么不用wpf。。。。

WPF 麻烦...
[/Quote]

你竟然说WPF麻烦…………winform做出来的动画效果很生硬的,他们本身就是用的WPF,比如迅雷
mrsupersky 2012-04-11
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 的回复:]

为什么不用wpf。。。。
[/Quote]
WPF 麻烦...
yuandonghuia 2012-04-11
  • 打赏
  • 举报
回复
为什么不用wpf。。。。
lfqsy 2012-04-11
  • 打赏
  • 举报
回复
那个效果好,渐变透明,上下自中消失,我也想弄个
dali_yan 2012-04-10
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 的回复:]

引用 2 楼 的回复:
if (true)为什么这里为true
{
if (Opacity + 0.1 >= 1.0)
{
Opacity -= 0.1;

}
else这里无法问
{
Opacity = 0.0;
timer1.Stop();

}

+1 true永远为真 不需要if了
[/Quote]
后面还有个else,是和前面的if匹配的,true是必要的,否则无法访问else的内容
orochiheart 2012-04-10
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 的回复:]
if (true)为什么这里为true
{
if (Opacity + 0.1 >= 1.0)
{
Opacity -= 0.1;

}
else这里无法问
{
Opacity = 0.0;
timer1.Stop();

}
[/Quote]
+1 true永远为真 不需要if了
mfkuyg61 2012-04-10
  • 打赏
  • 举报
回复
if (true)为什么这里为true
{
if (Opacity + 0.1 >= 1.0)
{
Opacity -= 0.1;

}
else这里无法问
{
Opacity = 0.0;
timer1.Stop();

}
dali_yan 2012-04-10
  • 打赏
  • 举报
回复
没有谁讨论一下吗?
Wrox Press, 2009,asp.net最新红宝书!7z压缩 Professional ASP.NET 3.5 SP1 In C# and VB ASP.NET 3.5 brings the power of Visual Studio® 2008 along with the multitude of language improvements in C# 2008 and Visual Basic® 2008 as well as powerful new technology called LINQ, together with the ASP.NET 2.0 Framework you already know and love. Packed with valuable coverage of ASP.NET 3.5 SP1, this essential resource offers both C# and VB examples throughout the book, and shares new and updated content on the ADO.NET Entity Framework, ADO.NET Dynamic Data, and ADO.NET Data Services. While ASP.NET 3.5 boasts server controls like the ListView and the incredibly flexible GridView, it also includes advancements in AJAX technology combined with JavaScript® debugging features in Visual Studio 2008. With this book, a stellar author team covers the new controls in the AJAX toolbox, the back button history, and script combining, and they also examine the new capabilities of WCF including changes to DataContractSerializer. In addition, the accompanying CD-ROM features the entire book in PDF format. What you will learn from this book * The concepts underlying the server control and its pivotal role in ASP.NET development * How to create templated ASP.NET pages using the master page feature * How to work with data from enterprise databases including SQL Server® * Ways to debug, package, and deploy ASP.NET applications, monitor their health and performance, and handle errors * How to retrieve, update, and delete data quickly and logically using LINQ with side-by-side examples comparing LINQ to existing techniques * Ways to localize your web site in multiple languages for a world-wide audience * Methods for adding AJAX capabilities to your ASP.NET applications * The many benefits of the new data access additions * Ways to use and extend the Provider Model for accessing data stores, processes, and more * What freeware tools you need in Scott Hanselman's ASP.NET Ultimate Developer Tools appendix

110,536

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧