我一直在尝试制作一个使您对图像做出反应的程序。为了做到这一点,我需要在按键创建的公共表格中使用char。我不希望图像出现在钥匙出版社。
这是我的代码:
public Form1()
{
InitializeComponent();
this.BackgroundImage = Directions.Images[8];
}
public void Form1_KeyDown(object sender, KeyEventArgs e)
{
//pijlrichting links rechts boven onder c-links c-rechts c-boven c-onder
//goede controls links rechts boven onder c-onder c-boven c-links c-rechts
char c = Convert.ToChar(e.KeyCode);
Random number = new Random();
int direction = number.Next(0, 8);
this.BackgroundImage = Directions.Images[direction];
int[] controls = new int[] { 97, 100, 119, 115, 115, 119, 97, 100 };
if(controls[direction] == c)
{
}
}
不可能在form1()中使用键按事件中的变量,因为form1()是表单的构造函数,并且始终称为first,并且键按事件是在构造函数之后调用的。