using System;
using System.Drawing;
using System.Windows.Forms;
namespace WindowsFormsApplication
{
public partial class Form1 : Form
{
private Timer timer;
private int count = 0;
private int count_max = 10;
private int orgX;
private int orgY;
public Form1()
{
InitializeComponent();
this.Move += (s, e) => {
if (!timer.Enabled)
{
orgX = this.Location.X;
orgY = this.Location.Y;
}
};
timer = new Timer();
timer.Tick += (s,e)=> {
Point p =Location;
if((count&1)==0)
{
p.Offset(2, 2);
}
else
{
p.Offset(-2, -2);
}
Location = p;
count++;
if(count>=count_max)
{
count = 0;
timer.Stop();
Location = new Point(orgX, orgY);
}
};
timer.Interval = 25;
}
private void button1_Click(object sender, EventArgs e)
{
if(!timer.Enabled)
{
timer.Start();
}
}
}
}
More than 3 years have passed since last update.
Register as a new user and use Qiita more conveniently
- You get articles that match your needs
- You can efficiently read back useful information
- You can use dark theme