码迷,mamicode.com
首页 > Windows程序 > 详细

c#制作飘动动画窗体

时间:2017-02-11 00:43:43      阅读:267      评论:0      收藏:0      [点我收藏+]

标签:int   动画   new   d3d   事件   工具   ble   padding   src   

  1. 先在vs里创建一个项目,项目的类型选择vc#,创建一个windows窗体应用程序如下图:

    技术分享

  2. 单击确定后,在窗体中设置窗体内容,从工具箱向窗体添加三个计时器,如下图:技术分享

  3. 在窗体空白处,单击鼠标右键,单击“查看代码”,在初始化函数下添加如下代码:如下图:技术分享

    代码如下:

    int ScreenWidth = SystemInformation.PrimaryMonitorMaximizedWindowSize.Width;   //屏幕的宽度

     int ScreenHeight=SystemInformation.PrimaryMonitorMaximizedWindowSize.Heigh;//屏幕的高度

  4. 双击timer1,在事件函数里添加如下代码,如下图:技术分享

    代码如下:

     Point MyPos = new Point(this.DesktopLocation.X, this.DesktopLocation.Y);       //窗体的当前位置

                if (MyPos.X + Width < ScreenWidth)

                {

                    this.DesktopLocation = new Point(MyPos.X + 1, MyPos.Y);

                }

                else

                {

                    this.DesktopLocation = new Point(0, 0);

                }

     

  5. 双击“水平飘动”,在事件函数里添加如下代码,如下图:技术分享

  6. 代码如下:

                this.timer1.Enabled = true;

                this.timer2.Enabled = false;

                this.timer3.Enabled = false;

  7. 同理双击“垂直飘动”添加代码:

                 this.timer1.Enabled  = false ;

                this.timer2.Enabled = true ;

                this.timer3.Enabled = false;

  8. 双击timer2,在事件响应函数添加如下代码,如下图:技术分享代码如下:

     Point MyPos = new Point(this.DesktopLocation.X, this.DesktopLocation.Y);       //窗体的当前位置

                if ( MyPos.Y + Height < ScreenHeight)

                {

                    this.DesktopLocation = new Point(MyPos.X, MyPos.Y + 1);

                }

                else

                {

                    this.DesktopLocation = new Point(0, 0);

                }

  9. 同理双击timer3,添加如下代码:

     Point MyPos = new Point(this.DesktopLocation.X, this.DesktopLocation.Y);       //窗体的当前位置

                if (MyPos.X + Width < ScreenWidth || MyPos.Y + Height < ScreenHeight)

                {

                    this.DesktopLocation = new Point(MyPos.X + 1, MyPos.Y + 1);

                }

                else

                {

                    this.DesktopLocation = new Point(0, 0);

                }

     

  10. 然后双击“飘动窗体”添加如下代码:

               this.timer1.Enabled = false ;

                this.timer2.Enabled = false;

                this.timer3.Enabled = true ;

  11. 同理双击停止飘动,添加如下代码:

                 this.timer1.Enabled = false ;

                this.timer2.Enabled = false;

                this.timer3.Enabled = false;

  12. 最后在窗体上空白处双击,创建Form1_Load事件,添加如下代码,如下图:技术分享

    代码如下:this.timer1.Enabled = true;

  13. 开始调试,运行结果如下图:

    技术分享

c#制作飘动动画窗体

标签:int   动画   new   d3d   事件   工具   ble   padding   src   

原文地址:http://www.cnblogs.com/wanzhongjun/p/6388362.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!