c# - How do I fix this 'no overload for pictureBox_1 matches delegate 'System.Event.Handler'' -
i have been trying teach myself c# through tutorials , website , didn't know how make "character" move using arrow keys copied code here hoping work , fine until run , throws me error
error 1 no overload 'picturebox1_click' matches delegate 'system.eventhandler' c:\users\collin\documents\visual studio 2013\projects\my_rpg\my_rpg\form1.designer.cs 80 39 my_rpg
here code copied (i did change name whatever picturebox1 correct"
public mainscreen() { initializecomponent(); keydown += new keyeventhandler(mainscreen_keydown); if (charactercreated == false) { playgamebtn.forecolor = color.gray; } } private void picturebox1_click(object sender, keyeventargs e) { int x = picturebox1.location.x; int y = picturebox1.location.y; if (e.keycode == keys.right) { x += 2; } else if (e.keycode == keys.left) { x -= 2; } else if (e.keycode == keys.up) { y += 2; } else if (e.keycode == keys.down) { y -= 2; } picturebox1.location = new system.drawing.point(x, y); } and if click on error sends me line of code if edit throws me errors
this.picturebox1.click += new system.eventhandler(this.picturebox1_click);
the signature picturebox click event wants method receives object , eventargs parameter.
your code declares picturebox_click method object , keyeventargs. of course compiler not happy , tells not should be.
from code, seems want handle keydown event @ form level, need change code have method handle keydown event , restore original signature picture box
public mainscreen() { initializecomponent(); keydown += new keyeventhandler(mainscreen_keydown); if (charactercreated == false) { playgamebtn.forecolor = color.gray; } } private void picturebox1_click(object sender, eventargs e) { // remove code event , move mainscreen_keydown event } private void mainscreen_keydown(object sender, keyeventargs e) { int x = picturebox1.location.x; int y = picturebox1.location.y; if (e.keycode == keys.right) { x += 2; } else if (e.keycode == keys.left) { x -= 2; } else if (e.keycode == keys.up) { y += 2; } else if (e.keycode == keys.down) { y -= 2; } picturebox1.location = new system.drawing.point(x, y); } also, keep in mind, receive keydown events @ form level need set form.keypreview property true
Comments
Post a Comment