C#闪屏

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 WindowsFormsApplication1
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}

int x = 0;//记录窗体的原始位置
int y = 0;
private void button1_Click(object sender, EventArgs e)
{
//1、启动
x = this.Left;
y = this.Top;
timer1.Start();
}
//2用i来控制我timer跑到那个点
int i = 0;
int count = 0;
//3、把所有的点定义出来
Point[] ps = { new Point(-10, 0), new Point(-7, -7), new Point(0, -10), new Point(7, -7), new Point(10, 0), new Point(7, 7), new Point(0, 10), new Point(-7, 7) };

private void timer1_Tick(object sender, EventArgs e)
{
//4、将窗体设置为第i个点的位置

this.Left = x + ps[i].X;
this.Top = y + ps[i].Y;
i++;
if (i == 8)
{
i = 0;
count++;

}

if (count == 3)//三圈
{
this.Left = x;//窗体要停止到没有转之前的位置
this.Top = y;
count = 0;
timer1.Stop();//不转了
}





}

private void Form2_Load(object sender, EventArgs e)
{

}

}
}

你可能感兴趣的:(C#)