C#实现窗口抖动

来源:互联网 发布:什么软件商城最好用 编辑:程序博客网 时间:2024/05/13 02:30

C# 先从几个基础的小游戏开始,毕竟实践出真知,本节主要讲窗口抖动,代码如下

using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Windows.Forms;//导入命名空间using System.Threading;namespace 窗口抖动{    public partial class Form1 : Form    {        public Form1()        {            InitializeComponent();        }        //x位抖动速度,单位是像素,y为时间间隔,单位是毫秒        int x = 5;        int y = 10;        private void Form1_Load(object sender, EventArgs e)        {        }        //添加一个按钮,实现抖动的开始        private void button1_Click(object sender, EventArgs e)        {            button1.Text = "开始抖动";            //死循环实现一直抖动            for (; ; )            {                this.Left += x;                //sleep方法需要导入命名空间System.Threading                Thread.Sleep(y);                this.Top += x;                Thread.Sleep(y);                this.Left -= x;                Thread.Sleep(y);                this.Top -= x;                Thread.Sleep(y);            }        }    }}

运行结果
本节主要了解窗体应用程序,对其使用方法以及特点有一个基础的认识

1 0
原创粉丝点击