Как заставить графические блоки перемещаться из одной фиксированной точки в другую фиксированную точку?
У меня есть четыре коробки с картинками
1 2 4 3
в указанный формат.
когда я нажимаю на кнопку, она поворачивает мои графические поля только один раз, как это
2 3 1 4
и таймер запустится и будет считать до 3 секунд, а затем автоматически нажимает мою кнопку, чтобы повернуть снова, но в этом случае мой код неверен, пожалуйста, помогите, чтобы я мог повернуть эту картинку коробки случайное количество раз?
Что я уже пробовал:
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 MoveBox { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { if (pictureBox1.Location.Equals(pictureBox1.Location)) { //This swaps positions of picture boxes clockwise // first -90 degree rotation of four boxes pictureBox1.Location = new Point(0, 160); pictureBox2.Location = new Point(0, 0); pictureBox3.Location = new Point(180, 0); pictureBox4.Location = new Point(180, 160); moveTimer1.Enabled = true; } else if (pictureBox1.Location.Equals(pictureBox3.Location)) { //This swaps positions of picture boxes clockwise // second -90 degree rotation of four boxes pictureBox1.Location = new Point(0, 0); pictureBox2.Location = new Point(180, 0); pictureBox3.Location = new Point(180, 160); pictureBox4.Location = new Point(0, 160); } } private void moveTimer1_Tick(object sender, EventArgs e) { int timer = Convert.ToInt32(label1.Text); label1.Text = Convert.ToString(timer + 1); while (timer == 3) { moveTimer1.Enabled = false; button1.PerformClick(); } } } }
Richard MacCutchan
while (timer == 3)
Вы будете перемещать ящики только в том случае, если таймер равен 3, Что произойдет только один раз.