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

  • 相关阅读:
    基础知识回顾系列
    抽象类与接口的区别
    SharePoint 2010 PowerShell 系列 之 Create List and Field Lookup
    结构与类
    SharePoint 2010 PowerShell 系列 之 Create List and Field
    用C#构造HighChart类库,把数据转换成JSON第一阶段失败告终
    值类型 与 引用类型 的区别
    枚举与常量
    SharePoint 2010 PowerShell 系列 之 Create WebApplication
    SharePoint 2010 列表字段之KPI
  • 原文地址:https://www.cnblogs.com/wanzhongjun/p/6388362.html
Copyright © 2011-2022 走看看