日期:2014-05-18 浏览次数:20841 次
private void Form1_Load(object sender, EventArgs e) { Thread t = new Thread(new ThreadStart(DoMoveButton)); t.IsBackground = true; t.Start(); } private void DoMoveButton() { int x = 0; MoveControl dele = SafeRemove; while (true) { Point buttonPosition = button1.Location; if (buttonPosition.X <= 0) { x = panel1.Location.X + panel1.Width; } else { x = buttonPosition.X - 2; } Point p = new Point(x, buttonPosition.Y); button1.Invoke(dele, p); Thread.Sleep(100); } } public delegate void MoveControl(Point p); private void SafeRemove(Point p) { button1.Location = p; }