Witam,
Próbuję zrobić animację. Po naciśnięciu przycisku odpala się timer, który co 100 milisekund odpala metodę która powinna ruszyć PictureBox z moim obrazkiem w lewo. Kiedy tą samą instrukcje podepnę bezpośrednio pod przycisk obrazek rusza się tak jak chcę, jednak kiedy chcę aby timer ją wywoływał konsola wyrzuca mi
Exception thrown: 'System.InvalidOperationException' in System.Windows.Forms.dll
Używam MS Visual Studio 15.
Czy ktoś może naprowadzić mnie na rozwiązanie, albo napisać gdzie leży problem?
Zamieszczam kod poniżej.
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 WindowsFormsApplication1
{
public partial class Form1 : Form
{
private System.Timers.Timer doors0;
public Form1()
{
InitializeComponent();
doors0 = new System.Timers.Timer();
doors0.Interval = 100;
doors0.Elapsed += new System.Timers.ElapsedEventHandler(this.D0timer_Tick);
}
void D0timer_Tick(object sender, EventArgs e)
{
leftDoor0.Location = new Point(leftDoor0.Left - 1, leftDoor0.Top);
}
private void button1_Click(object sender, EventArgs e)
{
doors0.Start();
}
private void button2_Click(object sender, EventArgs e)
{
doors0.Enabled = false;
}
}
}