C#简单的动画效果_.NET WinForm窗体或控件动画实例
2014-11-12 16:19:55 By: shinyuu
介绍
目前有很多的简单的技术可以让你的Windows应用程序实现动画效果、在这里、我可以解释一个简单的动画(移动特效)技术给你的Windows窗体或任何其他控件
源代码分析
请按照下列步骤操作:
1、创建一个解决方案(如:SimpleAnimation)
2、将您的控件拖放在你的Windows窗体就可以了
例如:
Split - scnrMain
Buttons - btnAnimation1,btnAnimation2,btnReset,btnQuit
Panel - pnlMain
3、添加一个计时器控件(如:tmrMain)
4、编写代码如下
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace SimpleAnimation { public partial class frmMain : Form { int scnrWidth; int scnrHeight; int pnlWidth; int pnlHeight; public frmMain() { InitializeComponent(); } public void frmMain_Load(object sender, EventArgs e) { pnlMain.Width = 0; pnlMain.Height = 0; scnrWidth = scnrMain.Panel2.Width; scnrHeight = scnrMain.Panel2.Height; pnlWidth = pnlMain.Width; pnlHeight = pnlMain.Height; } private void btnShowPanel_Click(object sender, EventArgs e) { tmrMain.Enabled = true; btnAnimation1.Enabled = false; } private void tmrMain_Tick(object sender, EventArgs e) { while(pnlWidth < scnrWidth || pnlHeight < scnrHeight) { if (pnlMain.Width < scnrWidth) { pnlMain.Width = pnlWidth 1; pnlWidth ; } if (pnlMain.Height < scnrHeight) { pnlMain.Height = pnlHeight 1; pnlHeight ; } break; } } private void btnShowAnotherPanel_Click(object sender, EventArgs e) { pnlMain.Height = scnrHeight; while (pnlMain.Width < scnrWidth) { pnlMain.Width ; } btnAnimation2.Enabled = false; } private void btnReset_Click(object sender, EventArgs e) { pnlMain.Width = 0; pnlMain.Height = 0; scnrWidth = scnrMain.Panel2.Width; scnrHeight = scnrMain.Panel2.Height; pnlWidth = pnlMain.Width; pnlHeight = pnlMain.Height; btnAnimation1.Enabled = true; btnAnimation2.Enabled = true; tmrMain.Enabled = false; } private void btnQuitApp_Click(object sender, EventArgs e) { while (this.Height>60) { this.Height--; } Application.Exit(); } } }
最后给大家献上源代码下载链接: http://dwtedx.com/download.html?bdkey=s/1dD0AjZV 密码: r47y
若资源对你有帮助、浏览后有很大收获、不妨小额打赏我一下、你的鼓励是维持我不断写博客最大动力
想获取DD博客最新代码、你可以扫描下方的二维码、关注DD博客微信公众号(ddblogs)
或者你也可以关注我的新浪微博、了解DD博客的最新动态:DD博客官方微博(dwtedx的微博)
如对资源有任何疑问或觉得仍然有很大的改善空间、可以对该博文进行评论、希望不吝赐教
为保证及时回复、可以使用博客留言板给我留言: DD博客留言板(dwtedx的留言板)
感谢你的访问、祝你生活愉快、工作顺心、欢迎常来逛逛