zoukankan      html  css  js  c++  java
  • c#制作飘动动画窗体

    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. 开始调试,运行结果如下图:

  • 相关阅读:
    HNU 12906 Battleship
    codeforces 261 D
    HDU 4939 Stupid Tower Defense(dp)
    HDU 4941 Magical Forest(map映射+二分查找)杭电多校训练赛第七场1007
    HDU 4902 Nice boat 2014杭电多校训练赛第四场F题(线段树区间更新)
    【转载】使用Pandas对数据进行筛选和排序
    【转载】使用pandas进行数据清洗
    【转载】VC维的来龙去脉
    Python-时间操作
    Pandas-数据导入
  • 原文地址:https://www.cnblogs.com/wanzhongjun/p/6388362.html
Copyright © 2011-2022 走看看