C# STUDY

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);

        }

    }

}



本文转自莫水千流博客园博客,原文链接:http://www.cnblogs.com/zhoug2020/p/5875950.html,如需转载请自行联系原作者

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值