I tried searching all over the site but couldn't really find an answer to this question, I'm trying to make my Ellipse move by using the arrowkeys, but I keep getting the same error whatever I try.
Also, I get this error when I put this in my Canvas code in the XAML
KeyDown="movement"
Error:
No overload for 'movement' matches delegate 'System.Windows.Input.KeyEventHandler'
Code:
public MainWindow()
{
InitializeComponent();
x = 10;
y = 10;
diameter = 10;
DrawBall(x, y, diameter);
}
private void movement(object sender, System.Windows.Forms.KeyEventArgs key)
{
if (key.KeyCode == Keys.Up)
{
x -= 20;
}
else if (key.KeyCode == Keys.Down)
{
x += 20;
}
else if (key.KeyCode == Keys.Left)
{
y -= 20;
}
else if (key.KeyCode == Keys.Right)
{
y += 20;
}
DrawBall(x, y, diameter);
}
private void DrawBall(double x, double y, double diameter)
{
ballCanvas.Children.Clear();
Ellipse ellipse = new Ellipse();
ellipse.Stroke = new SolidColorBrush(Colors.Black);
ellipse.Fill = new SolidColorBrush(Colors.Red);
ellipse.Width = diameter;
ellipse.Height = diameter;
ellipse.Margin = new Thickness(x, y, 0, 0);
ballCanvas.Children.Add(ellipse);
}
}
}