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;
namespace WindowsFormsApplication3
{
public partial class Form1 : Form
{
public delegate void TimerHandler();
public event TimerHandler m_TimerEvent;
public int m_offset;
private System.Timers.Timer m_timer;
private List<System.Drawing.Point> m_orinLocation;
private List<System.Windows.Forms.Button> m_Buttons;
public Form1()
{
InitializeComponent();
m_timer = new System.Timers.Timer(50);
m_timer.Elapsed += new System.Timers.ElapsedEventHandler(theout);
m_timer.Enabled = true;
m_orinLocation = new List<System.Drawing.Point>();
m_Buttons = new List<System.Windows.Forms.Button>();
m_orinLocation.Add(button1.Location);
m_orinLocation.Add(button2.Location);
m_orinLocation.Add(button3.Location);
m_orinLocation.Add(button4.Location);
m_orinLocation.Add(button5.Location);
m_orinLocation.Add(button6.Location);
m_orinLocation.Add(button7.Location);
m_orinLocation.Add(button8.Location);
m_orinLocation.Add(button9.Location);
m_Buttons.Add(button1);
m_Buttons.Add(button2);
m_Buttons.Add(button3);
m_Buttons.Add(button4);
m_Buttons.Add(button5);
m_Buttons.Add(button6);
m_Buttons.Add(button7);
m_Buttons.Add(button8);
m_Buttons.Add(button9);
m_offset = 0;
m_TimerEvent += process;
}
public void process()
{
m_timer.Enabled = false;
int itemHeight = this.button1.Height;
System.Console.WriteLine("Process m_offset{0}, mod{1}", m_offset, m_offset % itemHeight);
m_offset += itemHeight / 2;
if (m_offset >= itemHeight)
{
m_offset = 0;
for (int i = 0; i < 9; ++i)
{
m_Buttons[i].Location = new System.Drawing.Point(m_orinLocation[i].X, m_orinLocation[i].Y);
}
}
else
{
for (int i = 0; i < 9; ++i)
{
m_Buttons[i].Location = new System.Drawing.Point(m_orinLocation[i].X, m_orinLocation[i].Y - m_offset);
}
}
m_timer.Enabled = true;
}
public void theout(object source, System.Timers.ElapsedEventArgs e)
{
try
{
if (m_TimerEvent != null)
this.Invoke(m_TimerEvent);
}
catch(System.Exception err)
{
Console.WriteLine("{0}",err.Message);
}
}
private void button10_Click(object sender, EventArgs e)
{
}
protected override void OnClosing(CancelEventArgs e)
{
m_timer.Stop();
m_timer.Close();
m_TimerEvent = null;
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
}
}
}
C# STUDY
最新推荐文章于 2021-07-09 11:32:13 发布